update metrics
This commit is contained in:
parent
78984cb11e
commit
d0e35852af
@ -164,19 +164,27 @@ def generate_revenue_dataset(dataset):
|
|||||||
"hardwareandaccessories": "Hardware & Accessories",
|
"hardwareandaccessories": "Hardware & Accessories",
|
||||||
"software": "Software",
|
"software": "Software",
|
||||||
"collectibles": "Collectibles",
|
"collectibles": "Collectibles",
|
||||||
|
"automotivesales": "Auto",
|
||||||
|
"energygenerationandstoragesegment": "Energy and Storage",
|
||||||
|
"servicesandother": "Services & Other",
|
||||||
|
"automotiveregulatorycredits": "Regulatory Credits",
|
||||||
|
"intelligentcloud": "Intelligent Cloud",
|
||||||
|
"productivityandbusinessprocesses": "Productivity & Business"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Filter out unwanted categories
|
# Filter out unwanted categories
|
||||||
excluded_names = {'compute', 'networking', 'cloudserviceagreements', 'digital', 'allother', 'preownedvideogameproducts'}
|
excluded_names = {'officeproductsandcloudservices','serverproductsandcloudservices','automotiverevenues','automotive','computeandnetworking','graphics','gpu','automotivesegment','energygenerationandstoragesales','energygenerationandstorage','automotivesaleswithoutresalevalueguarantee','salesandservices','compute', 'networking', 'cloudserviceagreements', 'digital', 'allother', 'preownedvideogameproducts'}
|
||||||
dataset = [revenue for revenue in dataset if revenue['name'].lower() not in excluded_names]
|
dataset = [revenue for revenue in dataset if revenue['name'].lower() not in excluded_names]
|
||||||
|
|
||||||
# Process and clean the dataset
|
# Process and clean the dataset
|
||||||
for item in dataset:
|
for item in dataset:
|
||||||
name = item.get('name').lower()
|
try:
|
||||||
value = int(float(item.get('value')))
|
name = item.get('name').lower()
|
||||||
if name in name_replacements:
|
value = int(float(item.get('value')))
|
||||||
item['name'] = name_replacements[name]
|
if name in name_replacements:
|
||||||
item['value'] = value
|
item['name'] = name_replacements[name]
|
||||||
|
item['value'] = value
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Group by name and calculate total value
|
# Group by name and calculate total value
|
||||||
name_totals = defaultdict(int)
|
name_totals = defaultdict(int)
|
||||||
@ -239,25 +247,27 @@ def generate_geography_dataset(dataset):
|
|||||||
aggregated_data = {}
|
aggregated_data = {}
|
||||||
|
|
||||||
for item in dataset:
|
for item in dataset:
|
||||||
# Standardize country names
|
try:
|
||||||
name = item.get('name', '').lower()
|
name = item.get('name', '').lower()
|
||||||
date = item.get('date')
|
date = item.get('date')
|
||||||
value = int(float(item.get('value', 0)))
|
value = int(float(item.get('value', 0)))
|
||||||
|
|
||||||
year = int(date[:4])
|
year = int(date[:4])
|
||||||
if year < 2019:
|
if year < 2019:
|
||||||
continue # Skip this item if the year is less than 2019
|
continue # Skip this item if the year is less than 2019
|
||||||
|
|
||||||
# Replace country name if necessary
|
# Replace country name if necessary
|
||||||
country_name = country_replacements.get(name, 'Other')
|
country_name = country_replacements.get(name, 'Other')
|
||||||
|
|
||||||
# Use (country_name, date) as the key to sum values
|
# Use (country_name, date) as the key to sum values
|
||||||
key = (country_name, date)
|
key = (country_name, date)
|
||||||
|
|
||||||
if key in aggregated_data:
|
if key in aggregated_data:
|
||||||
aggregated_data[key] += value # Add the value if the country-date pair exists
|
aggregated_data[key] += value # Add the value if the country-date pair exists
|
||||||
else:
|
else:
|
||||||
aggregated_data[key] = value # Initialize the value if new country-date pair
|
aggregated_data[key] = value # Initialize the value if new country-date pair
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Convert the aggregated data back into the desired list format
|
# Convert the aggregated data back into the desired list format
|
||||||
dataset = [{'name': country, 'date': date, 'value': total_value} for (country, date), total_value in aggregated_data.items()]
|
dataset = [{'name': country, 'date': date, 'value': total_value} for (country, date), total_value in aggregated_data.items()]
|
||||||
@ -364,6 +374,6 @@ if __name__ == "__main__":
|
|||||||
run('GME', custom_order)
|
run('GME', custom_order)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
for symbol in ['NVDA','AAPL','GME']:
|
for symbol in ['TSLA']: #['NVDA','AAPL','GME']:
|
||||||
run(symbol)
|
run(symbol)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user