Example #1
0
	def add_map(self,mapname):
		pattern = self._searchstring(mapname)
		result = self._proxy.springfiles.search(pattern)[0]
		name = result['name']
		nmap = Map()
		meta = result['metadata']
		nmap.startpos = [(f['x'],f['z']) for f in meta['StartPos'] ]
		nmap.name = name
		nmap.md5 = result['md5']
		try:
			imgurl = result['mapimages'][0]
			basedir = nmap.basedir(globe.config)
			basename = nmap.name + imgurl[-4:]
			local_fn = os.path.join( basedir, '1024', basename )
			globe.mkdir_p(local_fn)
			urllib.urlretrieve (imgurl, local_fn)
			img = Image.open(local_fn)
			for i in [128,256,512]:
				resized_img = img.resize((i, i), Image.ANTIALIAS)
				fn = os.path.join(basedir, str(i), basename)
				myutils.mkdir_p(fn)
				resized_img.save(fn)
			nmap.minimap = basename
		except Exception, e:
			globe.Log.exception(e)
			globe.Log.error('download for map %s failed'%nmap.name)
Example #2
0
def matches_per_player( playerid ):
	print 'not cached: matches_per_player( %s )'% playerid
	s = db.session()
	inc = timedelta(days=1)
	today = datetime.combine(date.today(), time.min ) #datetime( now.year, now.month, now.day )
	since = today - timedelta(days=7) - fail_offset
	now = since
	data = []
	i = 1
	while now < datetime.now() - fail_offset:
		data.append( s.query( Result.id ).filter( Result.player_id == playerid).filter( Result.date < now + inc ).filter( Result.date >= now ).count() )
		i += 1
		now += inc
	fn = 'images/plots/player_matches_%i.png'%int(playerid)
	path = os.path.join(config.get('ladder','base_dir'), fn)
	url = '%s/%s'%(config.get('ladder','base_url'), fn)
	mkdir_p(path)
	with mutex:
		f = plt.figure(1)
		plt.plot(range(len(data)),data)
		plt.ylabel('matches per day')
		plt.xlabel('days past')
		plt.savefig(path,transparent=True)
		plt.close(1)
	s.close()
	return url