Exemple #1
0
 def vars(self, req, data):
     # Sets up the variables for the google charts used in the
     # template
     v = {}
     # 440x220 is the max size
     us_map = MapChart(440, 220)
     us_map.geo_area = 'usa'
     items = data.states.counts()
     us_map.set_codes([state for count, state in items])
     us_map.add_data([count for count, state in items])
     us_map.set_colours(('EEEEEE', '0000FF', '000033'))
     v['us_map_url'] = us_map.get_url()
     country_map = MapChart(440, 220)
     items = data.countries.counts()
     country_map.set_codes([country_code for count, (country_name, country_code) in items])
     country_map.add_data([count for count, (country_name, country_code) in items])
     country_map.set_colours(('EEEEEE', '9999FF', '000033'))
     v['country_map_url'] = country_map.get_url()
     return v
Exemple #2
0
    data_dict = {}
    counter = 0
    for a in acc:
        #I = 100 + counter;
        #counter += 1
        I = a.get_current()
        a.I = I
        data_dict[a.isocode] = I

        print a.acronym, I, type(I)

    #url = http://chart.apis.google.com/chart?cht=map&cht=map:fixed=-60,-20,80,-35&chs=600x350&chd=s:9PfAu&chld=US-NY|CH|US-CA|AU-VIC|GB
    #chart.add_data_dict(data_dict)

    chart.add_data(data_dict.values())
    chart.set_codes(data_dict.keys())
    chart.zoom = '-60,-20,80,-35'

    counter = 0
    for k in data_dict.keys():
        for a in acc:
            if a.isocode == k:
                name = 'f%s:+%2.1f' % (a.acronym, a.I)

                if a.offset:
                    chart.add_marker(0, counter, name, '000000', 10,
                                     a.priority, a.offset)
                else:
                    chart.add_marker(0, counter, name, '000000', 10,
                                     a.priority)
            states['all'][state] = states['all'].get(state, 0) + quarter
        countries[tel][country] = countries[tel].get(country, 0) + quarter
        countries['all'][country] = countries['all'].get(country, 0) + quarter

    # write data to file
    country_file = open('projects_countries_' + mode + '.csv', 'w')
    country_file.write('tel,iso_country,q4\n')
    country_writer = csv.writer(country_file)
    for tel in telescopes:
        for country in country_list:
            country_writer.writerow([tel, country,
                                     '%.02f' % countries[tel][country]])

    # Now for the experimental chart generation.

    all_countries = copy.deepcopy(countries['all'])

    all_countries.pop('')
    chart = MapChart(440, 220)
    chart.set_colours(('FFFFFF', 'CCCCCC', '000000'))
    chart.set_codes(all_countries.keys())
    chart.add_data(all_countries.values())
    chart.download('projects_countries_all_telescopes_' + mode + '.png')

    all_countries.pop('US')
    chart = MapChart(440, 220)
    chart.set_colours(('FFFFFF', 'CCCCCC', '000000'))
    chart.set_codes(all_countries.keys())
    chart.add_data(all_countries.values())
    chart.download('projects_countries_foreign_all_telescopes_' + mode +'.png')
	data_dict = {}
	counter=0
	for a in acc:
		#I = 100 + counter;
		#counter += 1
		I = a.get_current()
		a.I = I
		data_dict[a.isocode] = I

		print a.acronym, I, type(I)

	#url = http://chart.apis.google.com/chart?cht=map&cht=map:fixed=-60,-20,80,-35&chs=600x350&chd=s:9PfAu&chld=US-NY|CH|US-CA|AU-VIC|GB
	#chart.add_data_dict(data_dict)

	chart.add_data(data_dict.values())
	chart.set_codes(data_dict.keys())
	chart.zoom = '-60,-20,80,-35'

	counter = 0	
	for k in data_dict.keys():	
		for a in acc:
			if a.isocode == k:
				name = 'f%s:+%2.1f'%(a.acronym,a.I)

				if a.offset:
					chart.add_marker(0,counter,name,'000000',10,a.priority,a.offset)
				else:
					chart.add_marker(0,counter,name,'000000',10,a.priority)
						
				counter = counter + 1