def _calc(): stats = {} if day_from is not None and day_to is not None: # fill in gaps for day in util.daterange(day_from,day_to): stats[day] = dict(total=0,done=0,help=0) # TODO: do the work in the database. q = session.query(cast(Article.pubdate,Date), Article) if day_from is not None: q = q.filter(cast(Article.pubdate, Date) >= day_from) if day_to is not None: q = q.filter(cast(Article.pubdate, Date) <= day_to) for day,art in q: if day not in stats: stats[day] = dict(total=0,done=0,help=0) stats[day]['total'] += 1 if not art.needs_sourcing: stats[day]['done'] += 1 stats = sorted([(day,row) for day,row in stats.iteritems()], key=lambda x: x[0], reverse=True ) return [DailyStats(x[0], x[1]['total'], x[1]['done']) for x in stats]
def users_daily(self): if self._dailyUniques or not self._logs: return self._dailyUniques for dt in util.daterange(self._logs[0][self.IDX_DATE], self._logs[-1][self.IDX_DATE]): self._dailyUniques.update({dt.strftime(self.D_FORMAT): 0}) for l in self._logs: dailyCount = self._dailyUniques[l[self.IDX_DATE].strftime(self.D_FORMAT)] self._dailyUniques.update({l[self.IDX_DATE].strftime(self.D_FORMAT): dailyCount + 1}) return self._dailyUniques
def generateUntil(self, endDay, minStartTime=None): """ Generate rides for all days from max(minStartDay, lastGeneratedDay) until endDay. """ assert not (self.lastGeneratedDay is None and minStartTime is None), "Need some starting point." if self.lastGeneratedDay is None: startDay = minStartTime.date() else: startDay = max(minStartTime.date(), self.lastGeneratedDay + timedelta(1)) for day in daterange(startDay, endDay): self.generateDay(day, minStartTime) self.lastGeneratedDay = day
def plottingDataSeries(request, project_id): traffic = [] subscriptions = [] date_range = util.get_reporting_dates(request) start = date_range['start'] end = date_range['end'] for single_date in util.daterange(start, end): traffic.append([util.unix_time_millis(single_date),random.randint(50, 150)]) subscriptions.append([util.unix_time_millis(single_date),random.randint(0, 2)]) data = [{"name": "data1", "data": get_google_stats(project_id, start, end)}, {"name": "data2", "data": get_conversions(project_id, start, end)}, {"name": "data3", "data": get_campaigns(project_id, start, end)}, # {"name": "data4", "data": get_subscriptions(project_id)}] {"name": "data4", "data": subscriptions}] return HttpResponse(json.dumps(data), content_type='application/json')
def __init__(self): '''generate_Y data as the following format feature[uid][T] is a list of features for user uid at time T the feature shoule be additive we remove register-only student from the dataset ''' self.feature = {} self.feature_num = 0 with open(COURSE_INFO_DIR) as f: courses = json.load(f) self.getUser() self.start = util.parseDate(courses[self.course]['start']) self.end = util.parseDate(courses[self.course]['end']) for uid in self.feature: for single_date in util.daterange(self.start, self.end): self.feature[uid][single_date] = [] logger.info('course: %s user: %d start: %s end: %s', self.course, len(self.feature), self.start.isoformat(), self.end.isoformat())
def __init__(self, course, configFile): '''generate_Y data as the following format feature[uid][T] is a list of features for user uid at time T the feature shoule be additive we remove register-only student from the dataset ''' self.course = course self.config = Config(course, configFile) self.feature = {} self.feature_num = 0 self.path = self.config.getJsonDir() self.getUser() self.start = self.config.getStart() self.end = self.config.getEnd() for uid in self.feature: for single_date in util.daterange(self.start, self.end): self.feature[uid][single_date] = [] logger.info('course: %s user: %d start: %s end: %s', self.course, len(self.feature), self.start.isoformat(), self.end.isoformat())
for which to look for satisfying taxicab trips.') args = parser.parse_args() start_date = args.start_date end_date = args.end_date coord_type = args.coord_type distance = args.distance if coord_type == 'pickups': coord_types = ['pickups'] elif coord_type == 'dropoffs': coord_types = ['dropoffs'] elif coord_type == 'both': coord_types = ['pickups', 'dropoffs'] start_date, end_date = date(*start_date), date(*end_date) fname = '_'.join([coord_type, str(distance), str(start_date), str(end_date)]) + '.csv' with open(os.path.join(output_path, fname), 'w') as to_write: writer = csv.writer(to_write) for day_idx, date in enumerate(daterange(start_date, end_date)): print('\n*** Date:', date, '***\n') current_fname = '_'.join(['_'.join(coord_types), str(distance), str(date)]) + '.csv' with open(os.path.join(output_path, current_fname), 'r') as to_read: reader = csv.reader(to_read) for row in reader: if len(row) != 0: writer.writerow([date] + row)