def get_context_data(self, **kwargs): context = super(ListView, self).get_context_data(**kwargs) activity = self.kwargs['activity'] stat = self.kwargs['stat'] activity_string = activities[activities_short.index(activity)] stat_string = stat_strings[stat] # Iterate over all dataflows and construct the relevant dataseries list f1 = Q(agg_level='Country') f2 = Q(activity=activity) series_list = DataSeries.objects.filter(f1 & f2) # series_list = DataSeries.objects.all() values = [] for series in series_list: # if series.region == '' and series.activity == activity: value = json.loads(series.metrics)[stat] values.append(value) print(stat) context.update({'stat': stat_string}) context.update({'activity': activity_string}) context.update({'values': values}) return context
def get_context_data(self, **kwargs): context = super(ListView, self).get_context_data(**kwargs) activity = self.kwargs['activity'] # Iterate over all dataflows and construct the relevant dataseries list f1 = Q(agg_level='Country') f2 = Q(activity=activity) series_list = DataSeries.objects.filter(f1 & f2) # series_list = DataSeries.objects.all() stats_list = [] for series in series_list: # if series.region == '' and series.activity == activity: stats = {} stats['name'] = country_dict[series.df_name] stats['Max'] = json.loads(series.metrics)['Max'] stats['Min'] = json.loads(series.metrics)['Min'] stats['Average'] = json.loads(series.metrics)['Mean'] stats['Latest'] = json.loads(series.metrics)['T'] stats['Vol'] = json.loads(series.metrics)['Vol'] stats_list.append(stats) activity_string = activities[activities_short.index(activity)] context.update({'activity': activity_string}) context.update({'stats_list': stats_list}) print(stats_list) return context
def get_context_data(self, **kwargs): context = super(DetailView, self).get_context_data(**kwargs) # get the geoslice geoslice = super(GSMapView, self).get_object() ac = geoslice.identifier.split('.')[1] # get the list of dataseries that are part of the geoslice dataseries = geoslice.dataset_id # print(dataseries) # construct the dataset to send to the template # the dataset for the mobility type for each country dataset = {} query = Q() for ds in dataseries: query |= Q(identifier=ds) entries = DataSeries.objects.filter(query) for full_entry in entries: print(full_entry) entry = {} # the redirect url in case we want to drill down entry['url'] = 'plot/' + full_entry.identifier # # we fetch the actual dataseries # full_entry = DataSeries.objects.filter(identifier=ds) # TBD dataid = full_entry.identifier.split('.')[0] # DS title entry['title'] = full_entry.title # DS long title entry['title_long'] = full_entry.title_long # DS observation dates entry['dates'] = full_entry.dates # DS observation values # values (% change) entry['values'] = full_entry.values # values (demeaned) dataset[dataid] = entry activity_dict = {} for i in activities_short: activity_dict[i] = activities[activities_short.index(i)] activity_string = activities[activities_short.index(ac)] context.update({'activity': activity_string}) context.update({'activity_dict': activity_dict}) context.update({'dataset': json.dumps(dataset)}) return context
def get_context_data(self, **kwargs): # Retrieve all dataflow objects and construct content description text for help display # object_list = DataFlow.objects.all() # statistics = {} # total_datasets = 0 # tracked_datasets = 0 # live_datasets = 0 # for df in object_list: # total_datasets += df.google_n # if df.tracked: # tracked_datasets += df.dashboard_n # live_datasets += len(df.dataset_id) # # statistics['total_datasets'] = total_datasets # statistics['tracked_datasets'] = tracked_datasets # statistics['live_datasets'] = live_datasets activity_dict = {} for i in activities_short: activity_dict[i] = activities[activities_short.index(i)] context = super(ListView, self).get_context_data(**kwargs) context.update({'activity_dict': activity_dict}) context.update({'activity': activities_short}) return context
def get_context_data(self, **kwargs): metadata = DashBoardParams.objects.all()[0].country_metadata print(metadata) context = super(ListView, self).get_context_data(**kwargs) activity1 = self.kwargs['activity1'] activity2 = self.kwargs['activity2'] activity_string1 = activities[activities_short.index(activity1)] activity_string2 = activities[activities_short.index(activity2)] # Filter the relevant dataseries list f1 = Q(agg_level='Country') f2 = Q(activity=activity1) f3 = Q(activity=activity2) series_list1 = DataSeries.objects.filter(f1 & f2) series_list2 = DataSeries.objects.filter(f1 & f3) N1 = len(series_list1) N2 = len(series_list2) dictionary_data = { 'A1': 'Minimum Observed ' + activity_string1 + ' Mobility', 'A2': 'Maximum Observed ' + activity_string1 + ' Mobility', 'A3': 'Average Observed Mobility for ' + activity_string1, 'A4': 'Latest Mobility Observation for ' + activity_string1, } stat_dict = {''} # All country dict policy1 = {} policy2 = {} i = 1 for series1 in series_list1: for series2 in series_list2: if series2.df_name == series1.df_name: # country data dict country_name = country_dict[series1.df_name] country1 = {} country1['A1'] = json.loads(series1.metrics)['Min'] country1['A2'] = json.loads(series1.metrics)['Max'] country1['A3'] = json.loads(series1.metrics)['Mean'] country1['A4'] = json.loads(series1.metrics)['T'] country1['M0'] = country_name country1['M1'] = metadata[ series1.df_name]['population_count'] try: country1['M2'] = metadata[ series1.df_name]['stress_level'] except: country1['M2'] = 0 country2 = {} country2['A1'] = json.loads(series2.metrics)['Min'] country2['A2'] = json.loads(series2.metrics)['Max'] country2['A3'] = json.loads(series2.metrics)['Mean'] country2['A4'] = json.loads(series2.metrics)['T'] country2['M0'] = country_name country1['M1'] = metadata[ series1.df_name]['population_count'] # country1['M2'] = metadata[series1.df_name]['stress_level'] # indexed by integer value policy1[str(i)] = country1 policy2[str(i)] = country2 i += 1 context.update({'policy1': policy1}) context.update({'policy2': policy2}) context.update({'dict_data': dictionary_data}) context.update({'activity1': activity_string1 + ' Mobility'}) context.update({'activity2': activity_string2 + ' Mobility'}) return context