class Ipv_Top: def __init__(self,files,top_x=20,db_settings=local_db_settings): self.data=IpCounter(files).get_data() self.top_x=sorted(self.data.items(),key=lambda x:x[1],reverse=True)[:top_x] self.connection = MySQL_Connection(db_settings) def store(self): keys='(day,topn,ip,freq)' for i,(ip,counts) in enumerate(self.top_x): self.connection.insert('top_ip',keys,(today,i+1,ip,counts))
class PV_analysis: def __init__(self, files, db_settings=local_db_settings): self.connection = MySQL_Connection(db_settings) self.data = Market_PV_Counter(files).get_data() def store(self): self.connection.update("T_Site", ["recent_visit_cnt"], ["0"], 'WHERE url != ""') for url, value in self.data.items(): with self.connection.connection as cursor: cursor.execute( 'UPDATE T_Site SET recent_visit_cnt = recent_visit_cnt+%d WHERE url LIKE "%%%s%%"' % (value, url) )
class IpLocationService: def __init__(self,files,db_settings=server_183_db_settings): self.data=IpLocationCounter(files).get_data() # self.data=cPickle.load(open('CityIpData')) self.connection=MySQL_Connection(db_settings) cPickle.dump(self.data,open('CityIpData','wb')) def store(self): province_data={} for (city,province),count in self.data.items(): self.connection.insert('city_ip',('day','city','count'),(today,city,count)) province_data.setdefault(province,0) province_data[province]+=count for province,count in province_data.items(): self.connection.insert('province_ip',('day','province','count'),(today,province,count)) # print self.data # print province_data
def __init__(self,files,db_settings=server_183_db_settings): self.data=IpLocationCounter(files).get_data() # self.data=cPickle.load(open('CityIpData')) self.connection=MySQL_Connection(db_settings) cPickle.dump(self.data,open('CityIpData','wb'))
def __init__(self,files,top_x=20,db_settings=local_db_settings): self.data=IpCounter(files).get_data() self.top_x=sorted(self.data.items(),key=lambda x:x[1],reverse=True)[:top_x] self.connection = MySQL_Connection(db_settings)
def __init__(self, files, db_settings=local_db_settings): self.connection = MySQL_Connection(db_settings) self.data = Market_PV_Counter(files).get_data()