def test_can_give_total_time_for_month(self): m = Month(2012, 10) w = Week() w.set_day(4, TimeRange(Time(7), Time(17, 10))) m.add_week(40, w) m.add_week(42, w) self.assertEquals(m.get_total_time(), Hours(20, 20))
def test_can_return_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals( m.get_week(40).get_day(0), TimeRange(Time(7), Time(17)))
def test_can_enter_times_into_first_incomplete_week(self): m = Month(2012, 11) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(8), Time(18))) m.add_week(44, w) self.assertEquals(m.get_day(1), TimeRange(Time(8), Time(18)))
def _get_assistance_week(self): w = Week() w.set_day(0, TimeRange(Time(13, 30), Time(17))) w.set_day(1, TimeRange(Time(6, 30), Time(8, 30))) w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(6, 30), Time(8, 30))) return w
def test_can_return_half_week(self): m = Month(2012, 11) w = Week() w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(8), Time(18))) m.add_week(44, w) self.assertEquals(m.get_week(44).get_day(2), None)
def test_can_enter_times_from_last_week_in_month(self): m = Month(2012, 10) w = Week() w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(7), Time(17))) m.add_week(44, w) self.assertEquals(m.get_day(31), TimeRange(Time(7), Time(17))) self.assertNotEquals(m.get_day(32), TimeRange(Time(7), Time(17)))
def test_uses_blocked_week_when_scheduling(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30))
def test_uses_taken_week_when_scheduling(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(17))
def test_doesnt_schedule_hours_scheduled_by_taken_week(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(47, 50)) self.assertEquals(w.get_total_time(), Hours(44, 20))
def test_returns_correctly_annotated_week_for_start_of_month(self): m = Month(2012, 11) w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) m.add_week(44, w) aw = m.get_week(44) self.assertEquals(aw.get_earliest_day_in_month(), 1) self.assertEquals(aw.get_first_valid_day(), 3) self.assertEquals(aw.get_last_valid_day(), 6)
def test_can_be_printed(self): w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) self.assertEquals(str(w), """M: 7:00-17:00 T: 7:00-17:00 O: 7:00-17:00 T: 7:00-17:00 F: 7:00-17:00 L: 7:00-17:00 S: 7:00-17:00""")
def test_first_day_is_shorter_if_day_is_taken(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week) ranges = [TimeRange(Time(17), Time(20)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(14))] for i in xrange(5): self.assertEquals(week.get_day(i), ranges[i])
def test_can_be_printed(self): w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) self.assertEquals( str(w), """M: 7:00-17:00 T: 7:00-17:00 O: 7:00-17:00 T: 7:00-17:00 F: 7:00-17:00 L: 7:00-17:00 S: 7:00-17:00""")
def test_first_day_is_shorter_if_day_is_taken(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week) ranges = [ TimeRange(Time(17), Time(20)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(14)) ] for i in xrange(5): self.assertEquals(week.get_day(i), ranges[i])
def test_can_be_concatenated(self): w1 = Week() w2 = Week() w1.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) w2.set_day(0, TimeRange(Time(13, 30), Time(17))) w1.set_day(1, TimeRange(Time(7), Time(12))) w2.set_day(2, TimeRange(Time(8), Time(13))) w3 = w1 + w2 self.assertEquals(w3.get_day(0), TimeRange(Time(8, 30), Time(17))) self.assertEquals(w3.get_day(1), TimeRange(Time(7), Time(12))) self.assertEquals(w3.get_day(2), TimeRange(Time(8), Time(13)))
def random_timetable(teachers, audiences, subjects, specialities): current_timetable = [] for speciality in specialities: days_in_week = [] for day in day_of_week: lessons_in_day = [] num_of_lessons = random.choice(range(1, 7)) for numb in range(num_of_lessons): num_of_lesson = random.choice(range(1, 7)) type_of_lesson = random.choice(l_or_p) subject = random.choice(subjects) teacher = random.choice(teachers) audience = random.choice(audiences) if type_of_lesson == 'practice': group = random.choice([1, 2]) lesson = Lesson(num_of_lesson, type_of_lesson, subject, teacher, audience, group) else: lesson = Lesson(num_of_lesson, type_of_lesson, subject, teacher, audience) lessons_in_day.append(lesson) current_day = Day(day, lessons_in_day) days_in_week.append(current_day) current_week = Week(speciality, days_in_week) current_timetable.append(current_week) timetable = Timetable(current_timetable) return timetable
def populateMedianWinnersForWeek(self, weekObject: Week): """given a week object, pull the median winners from it and populate the dictionary object Args: weekObject (Week): object to add wins for """ teams = weekObject.getWeekTopMedianScorers() self.MedianWinnersByWeek[weekObject.WeekIndex] = teams
def generate_week(hours, taken_week=None, latest_time=None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert (day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None generated_day = generate_day( longest_day if hours > longest_day else hours, taken_hours, latest_time) if generated_day.get_length().get_total_minutes() > 0: week.set_day(day, generated_day) day += 1 hours -= generated_day.get_length() return week
def test_generates_realistic_schedule(self): taken_week = Week() taken = [TimeRange(Time(8, 30), Time(13, 30)), TimeRange(Time(6, 30), Time(13, 30)), TimeRange(Time(7), Time(17)), TimeRange(Time(6, 30), Time(13, 30))] for i in xrange(len(taken)): taken_week.set_day(i, taken[i]) week = generate_week(Hours(30, 20), taken_week) ranges = [TimeRange(Time(13, 30), Time(20)), # 23:50 left TimeRange(Time(13, 30), Time(20)), # 17:20 left TimeRange(Time(17), Time(20)), # 14:20 left TimeRange(Time(13, 30), Time(20)), # 7:50 left TimeRange(Time(7), Time(14, 50))] # 0:00 left for i in xrange(len(ranges)): self.assertEquals(week.get_day(i), ranges[i])
def generate_week(hours, taken_week = None, latest_time = None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert(day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None generated_day = generate_day(longest_day if hours > longest_day else hours, taken_hours, latest_time) if generated_day.get_length().get_total_minutes() > 0: week.set_day(day, generated_day) day += 1 hours -= generated_day.get_length() return week
def test_respects_both_blocked_and_taken_weeks(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) taken = Week() taken.set_day(1, TimeRange(Time(7), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30)) self.assertEquals(w.get_day(1).get_start(), Time(17))
def test_generates_realistic_schedule(self): taken_week = Week() taken = [ TimeRange(Time(8, 30), Time(13, 30)), TimeRange(Time(6, 30), Time(13, 30)), TimeRange(Time(7), Time(17)), TimeRange(Time(6, 30), Time(13, 30)) ] for i in xrange(len(taken)): taken_week.set_day(i, taken[i]) week = generate_week(Hours(30, 20), taken_week) ranges = [ TimeRange(Time(13, 30), Time(20)), # 23:50 left TimeRange(Time(13, 30), Time(20)), # 17:20 left TimeRange(Time(17), Time(20)), # 14:20 left TimeRange(Time(13, 30), Time(20)), # 7:50 left TimeRange(Time(7), Time(14, 50)) ] # 0:00 left for i in xrange(len(ranges)): self.assertEquals(week.get_day(i), ranges[i])
def get_target_charts(self): firstPage = self.LastFmGet.user_recent_tracks(self.username, 100, 1) totalPages = int(firstPage['recenttracks']['@attr']['totalPages']) lastPage = self.LastFmGet.user_recent_tracks(self.username, 100, totalPages) firstScrobble = int( lastPage['recenttracks']['track'][-1]['date']['uts']) charts = [] chartsData = LastFmGet.user_weekly_chart_list(self.username) for chart in chartsData['weeklychartlist']['chart']: start = int(chart['from']) end = int(chart['to']) if end >= firstScrobble: charts.append(Week(start, end)) return charts
class Main(): if __name__ == '__main__': # This handles Twitter authentication and the connection to Twitter API # The API Key Information are stored in data/keys.json with open('../data/keys.json') as json_file: data = json.load(json_file) auth = OAuthHandler(data['consumer_key'], data['consumer_secret']) auth.set_access_token(data['access_token'], data['access_token_secret']) # Creates a new SearchAPI object and gets the previous tweets # searchAPI = SearchAPI() # searchAPI.getAccountsFollowers(auth, "KMbappe") dp = DataParser() nbFollowers = len(dp.getAllFollowers()) allTweets = dp.getAllTweets() week = Week() week.fill_week(allTweets) week.get_days_activity(nbFollowers) week.tuesday.getActivityOfTheHours()
def test_can_be_empty(self): w = Week() for i in xrange(7): self.assertEquals(w.get_day(i), None)
def test_can_hold_taken_week(self): y = Year(2012) taken = Week() y.add_taken(40, taken)
def test_can_hold_taken_week(self): taken = Week() wr = WeekRecord() wr.set_taken(taken)
def test_can_hold_blocked_ranges(self): y = Year(2012) blocked = Week() y.add_blocked(40, blocked) self.assertEquals(y.get_blocked(40), blocked)
def test_can_add_week_1_of_next_year_to_december(self): m = Month(2012, 12) w = Week() w.set_day(0, TimeRange(Time(7), Time(10))) m.add_week(1, w) self.assertEquals(m.get_day(31), TimeRange(Time(7), Time(10)))
def test_can_get_blocked_week(self): blocked = Week() wr = WeekRecord() wr.set_blocked(blocked) self.assertEquals(wr.get_blocked(), blocked)
crawler = WsjCrawler() crawl_all = False for p in products: crawled = crawler.crawl_by_dates( p, (datetime.today() - timedelta(days=1500)).date(), datetime.today().date()) if crawl_all else crawler.crawl(p) for x in crawled: cur.execute(x.db_save_command()) conn.commit() print("Crawling done.") today = (datetime.today() + timedelta(days=1, hours=16)).date() this_week = Week(today) weeks = [] for i in range(0, 100): this_week = this_week.prev_week() weeks.append(this_week) weeks.reverse() this_week = Week(today) for p in products: print("Analyzing {0}".format(p.name)) cur.execute( "select * from PRODUCT_QUOTE where PRODUCT_ID = {0} order by COB_DATE DESC LIMIT 1000" .format(p.id)) quotes = [] for i in cur.fetchall():
def test_can_report_total_hours_and_minutes(self): w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) w.set_day(1, TimeRange(Time(10), Time(10, 30))) self.assertEquals(w.get_total_time(), Hours(10, 30))
def test_can_retrieve_taken_week(self): y = Year(2012) taken = Week() y.add_taken(40, taken) self.assertEquals(y.get_taken(40), taken)
def test_can_set_day(self): w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) self.assertEquals(w.get_day(0), TimeRange(Time(7), Time(17)))
def test_can_enter_times_from_second_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(41, w) self.assertEquals(m.get_day(8), TimeRange(Time(7), Time(17)))
def _get_daycare_week(self): w = Week() w.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) w.set_day(1, TimeRange(Time(8, 30), Time(13, 30))) w.set_day(3, TimeRange(Time(8, 30), Time(13, 30))) return w
# # for i in m.get_week_numbers(): # year[2012].add_blocked(i, blocked2012) # year[2012].add_taken(i, taken2012) # blocked = {} blocked[2012] = {} blocked[2013] = {} taken = {} taken[2012] = {} taken[2013] = {} # October blocked[2012][40] = Week() blocked[2012][40].set_day(0, TimeRange(Time(8, 30), Time(13, 30))) blocked[2012][40].set_day(1, TimeRange(Time(8, 30), Time(13, 30))) blocked[2012][40].set_day(3, TimeRange(Time(8, 30), Time(13, 30))) taken[2012][40] = Week() taken[2012][40].set_day(1, TimeRange(Time(6, 30), Time(8, 30))) taken[2012][40].set_day(2, TimeRange(Time(7), Time(17))) blocked[2012][41] = Week() blocked[2012][41].set_day(0, TimeRange(Time(8, 30), Time(13, 30))) blocked[2012][41].set_day(1, TimeRange(Time(8, 30), Time(13, 30))) blocked[2012][41].set_day(3, TimeRange(Time(8, 30), Time(13, 30))) taken[2012][41] = Week() taken[2012][41].set_day(0, TimeRange(Time(13, 30), Time(17)))
def __init__(self): Week.__init__(self) self.set_first_valid_day(0) self.set_last_valid_day(6)
def test_can_add_week_52_of_previous_year_to_january(self): m = Month(2012, 1) w = Week() w.set_day(6, TimeRange(Time(7), Time(10))) m.add_week(52, w) self.assertEquals(m.get_day(1), TimeRange(Time(7), Time(10)))
def test_can_hold_blocked_week(self): blocked = Week() wr = WeekRecord() wr.set_blocked(blocked)
def test_can_return_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals(m.get_week(40).get_day(0), TimeRange(Time(7), Time(17)))
def test_can_be_modified_with_latest_time(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week, Time(22)) self.assertEquals(week.get_day(0), TimeRange(Time(17), Time(22)))
def test_returns_annotated_weeks(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals(type(m.get_week(40)), AnnotatedWeek)
def test_can_get_taken_week(self): taken = Week() wr = WeekRecord() wr.set_taken(taken) self.assertEquals(wr.get_taken(), taken)
def __init__(self): self.week = Week()