Пример #1
0
 def init_g2c_stats(self):
     if self._stats:
         return
     curves = g2c_db_curves()
     counts = self._counts
     total = counts["ncurves"]
     stats = {}
     dists = []
     # TODO use aggregate $group to speed this up and/or just store these counts in the database
     for attr in stats_attribute_list:
         counts = attribute_value_counts(curves, attr['name'])
         vcounts = []
         rows = []
         avg = 0
         for value,n in counts:
             prop = format_percentage(n,total)
             if 'avg' in attr and attr['avg']:
                 avg += n*value
             value_string = attr['format'](value) if 'format' in attr else value
             vcounts.append({'value': value_string, 'curves': n, 'query':url_for(".index_Q")+'?'+attr['name']+'='+str(value),'proportion': prop})
             if len(vcounts) == 10:
                 rows.append(vcounts)
                 vcounts = []
         if len(vcounts):
             rows.append(vcounts)
         if 'avg' in attr and attr['avg']:
             vcounts.append({'value':'\(\\mathrm{avg}\\ %.2f\)'%(float(avg)/total), 'curves':total, 'query':url_for(".index_Q") +'?'+attr['name'],'proportion':format_percentage(1,1)})
         dists.append({'attribute':attr,'rows':rows})
     stats["distributions"] = dists
     self._stats = stats
Пример #2
0
 def init_g2c_stats(self):
     if self._stats:
         return
     curves = g2c_db_curves()
     counts = self._counts
     total = counts["ncurves"]
     stats = {}
     dists = []
     # TODO use aggregate $group to speed this up and/or just store these counts in the database
     for attr in stats_attribute_list:
         counts = attribute_value_counts(curves, attr['name'])
         vcounts = []
         rows = []
         avg = 0
         for value,n in counts:
             prop = format_percentage(n,total)
             if 'avg' in attr and attr['avg']:
                 avg += n*value
             value_string = attr['format'](value) if 'format' in attr else value
             vcounts.append({'value': value_string, 'curves': n, 'query':url_for(".index_Q")+'?'+attr['name']+'='+str(value),'proportion': prop})
             if len(vcounts) == 10:
                 rows.append(vcounts)
                 vcounts = []
         if len(vcounts):
             rows.append(vcounts)
         if 'avg' in attr and attr['avg']:
             vcounts.append({'value':'\(\\mathrm{avg}\\ %.2f\)'%(float(avg)/total), 'curves':total, 'query':url_for(".index_Q") +'?'+attr['name'],'proportion':format_percentage(1,1)})
         dists.append({'attribute':attr,'rows':rows})
     stats["distributions"] = dists
     self._stats = stats
Пример #3
0
 def init_belyi_stats(self):
     if self._stats:
         return
     galmaps = belyi_db_galmaps()
     counts = self._counts
     total = counts["ngalmaps"]
     stats = {}
     dists = []
     # TODO use aggregate $group to speed this up and/or just store these counts in the database
     for attr in stats_attribute_list:
         counts = attribute_value_counts(galmaps, attr['name'])
         counts = [c for c in counts if c[0] != None]
         if len(counts) == 0:
             continue
         vcounts = []
         rows = []
         avg = 0
         total = sum([c[1] for c in counts])
         for value, n in counts:
             prop = format_percentage(n, total)
             if 'avg' in attr and attr['avg'] and (type(value) == int
                                                   or type(value) == float):
                 avg += n * value
             value_string = attr['format'](
                 value) if 'format' in attr else value
             vcounts.append({
                 'value':
                 value_string,
                 'curves':
                 n,
                 'query':
                 url_for(".index") + '?' + attr['name'] + '=' + str(value),
                 'proportion':
                 prop
             })
             if len(vcounts) == 10:
                 rows.append(vcounts)
                 vcounts = []
         if len(vcounts):
             rows.append(vcounts)
         if 'avg' in attr and attr['avg']:
             vcounts.append({
                 'value':
                 '\(\\mathrm{avg}\\ %.2f\)' % (float(avg) / total),
                 'galmaps':
                 total,
                 'query':
                 url_for(".index") + '?' + attr['name'],
                 'proportion':
                 format_percentage(1, 1)
             })
         dists.append({'attribute': attr, 'rows': rows})
     stats["distributions"] = dists
     self._stats = stats