def get(self): num_months = 3 now = datetime.datetime.now() assignment_query = Assignment.get_all() assignment_query.order("end_date") logging.info("it worked")
def get(self): manual = self.request.get("manual") == "1" num_months = 6 now = datetime.datetime.now().date() this_week = now - datetime.timedelta(days=now.weekday()) dmonth = this_week.month + num_months if dmonth > 11: dyear = this_week.year + 1 dmonth = dmonth - 11 else: dyear = this_week.year logging.info("{} {}".format(dyear,dmonth)) end_date = datetime.date(year=dyear, month=dmonth, day=1) logging.info(end_date) assignments = Assignment.gql("WHERE end_date > :1 ORDER BY end_date", now ) assignments = [ a for a in assignments if a.start_date.date() < end_date ] assignments = sorted(assignments, key=lambda a: a.project_name) one_week = datetime.timedelta(days=7) weeks = [] while this_week < end_date: this_weeks_assignments = [] for a in assignments: if a.start_date.date() <= this_week <= a.end_date.date() - datetime.timedelta(days=6): # a.weeks_remaining = ((a.end_date.date() - this_week).days + 1)/7 # logging.info(a.weeks_remaining) this_weeks_assignments.append(a) weeks.append((this_week, this_weeks_assignments)) this_week += one_week logging.info(weeks) calendar = Calendar.get_or_insert("main", title="Main Calendar Data") calendar.data = pickle.dumps(weeks) calendar.timestamp = datetime.datetime.now() calendar.manual = manual calendar.put() #delete all the NewAssignments that are now in the calendar db.delete(NewAssignment.all(keys_only=True)) if manual: self.redirect("/settings?status=calgen")
def populate(self): # country = self.request.get("country") # partner = self.request.get("partner") # project = self.request.get("project") # site = self.request.get("site") oneweek = datetime.timedelta(days=7) weeks = [ x[0] for x in self.calendar.monthdatescalendar(self.year, self.month) if x[0].month == self.month ] a_query = Assignment.get_all() #_all() a_query.filter("end_date >", weeks[0]) for week in weeks: a_query.filter("end_date >", week).order("end_date") # a_query = db.GqlQuery("SELECT * FROM Assignment WHERE start_date < :1 ORDER BY start_date, end_date DESC", week + oneweek) assignments = [a for a in a_query] assignments = filter(lambda a: week >= a.start_date.date(), assignments) # if country: # assignments = filter(lambda a: a.site.country == country, assignments) # if partner: # assignments = filter(lambda a: unicode(a.partner.key()) == unicode(partner), assignments) # if project: # assignments = filter(lambda a: unicode(a.project.key()) == unicode(project), assignments) # if site: # assignments = filter(lambda a: unicode(a.site.key()) == unicode(site), assignments) if len(assignments) > 0: # assignments = sorted(assignments, key=lambda a: a.site.country) assignments = sorted(assignments, key=lambda a: a.project.name) new_week = Week(week) new_week.setAssignments(assignments) self.addWeek(new_week)
def populate(self): # country = self.request.get("country") # partner = self.request.get("partner") # project = self.request.get("project") # site = self.request.get("site") oneweek = datetime.timedelta(days=7) weeks = [x[0] for x in self.calendar.monthdatescalendar(self.year, self.month) if x[0].month == self.month] a_query = Assignment.get_all()#_all() a_query.filter("end_date >", weeks[0]) for week in weeks: a_query.filter("end_date >", week).order("end_date") # a_query = db.GqlQuery("SELECT * FROM Assignment WHERE start_date < :1 ORDER BY start_date, end_date DESC", week + oneweek) assignments = [a for a in a_query] assignments = filter(lambda a: week >= a.start_date.date(), assignments) # if country: # assignments = filter(lambda a: a.site.country == country, assignments) # if partner: # assignments = filter(lambda a: unicode(a.partner.key()) == unicode(partner), assignments) # if project: # assignments = filter(lambda a: unicode(a.project.key()) == unicode(project), assignments) # if site: # assignments = filter(lambda a: unicode(a.site.key()) == unicode(site), assignments) if len(assignments) > 0: # assignments = sorted(assignments, key=lambda a: a.site.country) assignments = sorted(assignments, key=lambda a: a.project.name) new_week = Week(week) new_week.setAssignments(assignments) self.addWeek(new_week)
def get(self): years = self.request.get("years") confirm = self.request.get("confirm") arched_volunteers = 0 arched_assignments = 0 years = 1 if years == "" else int(years) assignments = Assignment.all() assignment_count = assignments.count() #cutoff = datetime.datetime.now() - datetime.timedelta(days=365*years) cutoff = datetime.datetime(years, 1, 1) assignments.filter("end_date <=", cutoff) assignments.order("end_date").order("start_date") logging.info(assignments.count()) archive = {} durations = {} #[{}, {}, {}, {}] volunteers = [] week = datetime.timedelta(weeks=1) for a in assignments: v = a.volunteer partner = a.partner_name if v not in volunteers: volunteers.append(v) yob = v.DOB.year country = v.country project_name = a.project_name s = a.start_date e = a.end_date year = s.year duration = e - s duration = duration.days slot_index = 8 for prop in (country, yob, partner, project_name): key = str(s.date()) if not archive.has_key(key): archive[key] = new_week() if archive[key][slot_index].has_key(prop): archive[key][slot_index][prop].append(duration) else: archive[key][slot_index][prop] = [duration] slot_index += 1 slot_index = 0 for prop in (country, yob, partner, project_name): if not durations.has_key(s.year): durations[year] = [{}, {}, {}, {}] if durations[year][slot_index].has_key(prop): durations[year][slot_index][prop].append(duration) else: durations[year][slot_index][prop] = [duration] slot_index += 1 key = str(s.date()) set_data(archive, key, country, yob, project_name, partner) while s < e: month = s.month - 1 key = str(s.date()) set_data(archive, str(s.date()), country, yob, project_name, partner, OCCUPANCY=True) s += week archive['durations'] = durations if confirm == "hellyes": a.delete() arched_assignments += 1 volunteer_data = [{}, {}] for v in volunteers: if confirm == "hellyes" and v.num_assignments == 0: v.delete() arched_volunteers += 1 dates = sorted(archive.keys( )) #filter(lambda key: key != "durations", sorted(archive.keys())) archive_years = {} for date in dates: year = date.split("-")[0] if archive_years.has_key(year): archive_years[year][date] = archive[date] else: archive_years[year] = {date: archive[date]} logging.info(durations.keys()) for year in sorted( filter(lambda key: key != "durations", archive_years.keys())): arch_ent = Archive.get_or_insert(year) this_arch = archive_years[year] this_arch['durations'] = durations[int(year)] if arch_ent.data is None: arch_ent.year = int(year) arch_ent.data = this_arch else: data = arch_ent.data logging.info(type(data)) for week in filter(lambda x: x != 'durations', this_arch.keys()): if data.has_key(week): for section in range(8): for key in this_arch[week][section].keys(): if data[week][section].has_key(key): logging.info(data) logging.info(week) logging.info(section) logging.info(key) data[week][section][key] += 1 else: data[week][section][key] = 1 else: data[week] = new_week() for section in range(8): for key in this_arch[week][section].keys(): if data[week][section].has_key(key): data[week][section][key] += 1 else: data[week][section][key] = 1 arch_ent.put()