def test_isEquinox(self):
     date = Date(9, 23, 2019)  # autumn equinox
     self.assertEqual(date.isEquinox(), True)
     date = Date(3, 21, 2019)  # spring equinox
     self.assertEqual(date.isEquinox(), True)
     date = Date(4, 4, 2019)
     self.assertEqual(date.isEquinox(), False)
 def test_isWeekDay(self):
     date = Date(1, 1, 2000)
     self.assertEqual(date.isWeekDay(), True)
     date = Date(1, 2, 2000)
     self.assertEqual(date.isWeekDay(), True)
     date = Date(1, 3, 2000)
     self.assertEqual(date.isWeekDay(), False)
Exemplo n.º 3
0
    def __apply_changes_to_options__(self):
        startdate = self.textbox_startdate.text()[:-6]
        enddate = self.textbox_enddate.text()[:-6]
        cbox_value = self.combobox_time_window.currentText()
        time_window = None
        if cbox_value == 'Default':
            time_window = 'D'
        elif cbox_value == 'Daily':
            time_window = 'd'
        elif cbox_value == 'Weekly':
            time_window = 'w'
        elif cbox_value == 'Monthly':
            time_window = 'm'

        year_s = int(startdate[-4:].replace("/", ""))
        month_s = int(startdate[3:5].replace("/", ""))
        day_s = int(startdate[0:2].replace("/", ""))

        year_e = int(enddate[-4:].replace("/", ""))
        month_e = int(enddate[3:5].replace("/", ""))
        day_e = int(enddate[0:2].replace("/", ""))

        new_date_start = Date(month_s, day_s, year_s)
        new_date_end = Date(month_e, day_e, year_e)
        #Get GUI values
        guistate = []
        guistate.append(self.checkbox_startdate.isChecked())
        guistate.append(self.checkbox_enddate.isChecked())
        guistate.append(self.radiobutton_custom_date.isChecked())
        guistate.append(self.radiobutton_real_money_gain.isChecked())
        #load new values
        self.options_image.setValues(new_date_start, new_date_end, time_window,
                                     guistate)
        #Change list of trades
        self.cw.reload_tabs(self.options_image)
Exemplo n.º 4
0
 def __init__(self, login):
     """Init account manager, loggin, parse empire"""
     # Create Selenium WebDriver
     self.navigate = Nav(login)
     # Connect to given account
     try:
         self.navigate.connect_to_account()
         log("OGameBot Logged in")
     except Exception as exc:
         log(exc)
     self.planet_list = self.get_planet_list()
     # Get build orders and fleet orders
     self.all_build_orders = units.build_order
     self.all_fleet_orders = units.fleet_order
     self.all_ghost_order = units.ghost_order
     # Init mutex and threads list
     self.mutex = Lock()
     self.thread_pool = list()
     # INIT TIME EVENT VARIABLES
     self.time_to_start_ghost = Date([23, 0, 0])
     self.time_to_end_ghost = Date([8, 0, 0]).get_next_day()
     # Init the building thread for each planet
     for planet, build_order in zip(self.planet_list,
                                    self.all_build_orders):
         self.thread_pool.append(
             Thread(target=self.build, args=(planet, build_order)))
     # Init the watcher thread
     self.thread_pool.append(
         Thread(target=self.check_new_event, args=(self.planet_list, )))
     # Init the farming and exploring thread
     self.thread_pool.append(
         Thread(target=self.send_fleet, args=(self.all_fleet_orders, )))
     # Init the event boolean
     self.is_event_over = False
 def test_isSummerSolstice(self):
     date = Date(6, 21, 2019)
     self.assertEqual(date.isSummerSolstice(), True)
     date = Date(5, 21, 2019)
     self.assertEqual(date.isSummerSolstice(), False)
     date = Date(6, 22, 2019)
     self.assertEqual(date.isSummerSolstice(), False)
 def test_isWinterSolstice(self):
     date = Date(12, 22, 2019)
     self.assertEqual(date.isWinterSolstice(), True)
     date = Date(1, 22, 2019)
     self.assertEqual(date.isWinterSolstice(), False)
     date = Date(12, 23, 2019)
     self.assertEqual(date.isWinterSolstice(), False)
 def test_numDay(self):
     date1 = Date(1, 1, 2000)
     date2 = Date(1, 2, 2000)
     # print(date1.julianDay())
     # print(date2.julianDay())
     self.assertEqual(date1.numDay(date2), 1)
     self.assertEqual(date2.numDay(date1), 1)
 def test_isAutumnEquinox(self):
     date = Date(9, 23, 2019)
     self.assertEqual(date.isAutumnEquinox(), True)
     date = Date(9, 21, 2019)
     self.assertEqual(date.isAutumnEquinox(), False)
     date = Date(3, 23, 2019)
     self.assertEqual(date.isAutumnEquinox(), False)
 def test_isSpringEquinox(self):
     date = Date(3, 21, 2019)
     # print(date.isSpringEquinox())
     self.assertEqual(date.isSpringEquinox(), True)
     date = Date(3, 20, 2019)
     self.assertEqual(date.isSpringEquinox(), False)
     date = Date(1, 20, 2019)
     self.assertEqual(date.isSpringEquinox(), False)
 def __init__(self):
     """
     docstring
     """
     self.name = str("Untitled")
     self.start_date = Date()
     self.due_date = Date()
     self.end_date = Date()
Exemplo n.º 11
0
 def __init__(self, firstName, lastName, birthMonth, birthDay, birthYear,
              hireMonth, hireDay, hireYear):
     "Constructor for class Employee"
     self.birthDate = Date(birthMonth, birthDay, birthYear)
     self.hireDate = Date(hireMonth, hireDay, hireYear)
     self.firstName = firstName
     self.lastName = lastName
     print("Employee constructor: %s %s" % (self.lastName, self.firstName))
Exemplo n.º 12
0
 def setUp(self):
     self.flight = Flight(start_time=Date(29, 11, 2016, hour='12:20'),
                          end_time=Date(29, 11, 2016, hour='15:30'),
                          passengers=100,
                          max_passengers=120,
                          from_dest="Sofia",
                          to_dest="London",
                          terminal=Terminal(2, 30),
                          declined=False)
Exemplo n.º 13
0
 def setUp(self):
     self.terminal = Terminal()
     self.flight = Flight()
     self.flight2 = Flight(start_time=Date(day=29,
                           month=11, year=2016, hour='17:30'),
                           from_dest="Vancouver", to_dest="New York",
                           end_time=Date(day=29, month=11,
                           year=2016, hour='20:40'))
     self.terminal.add_flight(self.flight)
     self.terminal.add_flight(self.flight2)
 def test_dayOfYear(self):
     date = Date(1, 1, 2000)
     # print(date.dayOfYear())
     self.assertEqual(date.dayOfYear(), 1)
     date = Date(1, 31, 2000)
     self.assertEqual(date.dayOfYear(), 31)
     date = Date(2, 29, 2000)
     self.assertEqual(date.dayOfYear(), 31 + 29)
     date = Date(3, 1, 2000)
     self.assertEqual(date.dayOfYear(), 31 + 29 + 1)
     date = Date(12, 31, 2000)
     self.assertEqual(date.dayOfYear(), 366)
    def test__init__(self):
        "docstring"
        date = Date(0,0,0)
        print(date._toGregorian())
        date = Date(0, 1, 2000)
        print(date._toGregorian())
        date = Date(1, 0, 2000)
        print(date._toGregorian())
        date = Date(1, 1, 0)
        print(date._toGregorian())

        print("init test done")
        print()
Exemplo n.º 16
0
def list_all_people(filename='people.csv', method='r', by='default'):
    """
    Reads the file and adds each line to the list as a Person object.

    Parameters:
    arg1 (string): The name of the file to open
    arg2 (string): Method to use when opening file
    arg2 (string): Sort criteria

    Returns:
    list: List of objects found in the csv file

    """

    people = list()
    with open(filename, method) as current:
        current.seek(0)
        for line in current:
            if line.rstrip() == 'name,last_name,birthday':
                continue
            props = line.split(',')
            date = props[2].split('.')
            people.append(
                Person(props[0], props[1],
                       Date(int(date[0]), int(date[1]), int(date[2]))))
    if by == 'first_name':
        people.sort(key=lambda x: x.name)
    elif by == 'last_name':
        people.sort(key=lambda x: x.last_name)
    return people
Exemplo n.º 17
0
 def test_get_flight_from_hour(self):
     destination = self.flight.from_dest
     date = Date()
     hour = '12:31'
     self.assertEqual(self.terminal.
                      get_flight_from_hour(destination, date, hour),
                      [self.flight])
def gather_messages(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,eventdate FROM mit.appmessages WHERE eventdate < '2017-09-26 00:00:00' AND eventdate > '2016-12-06 00:00:00'")#Execute query
    data = cur.fetchone()
    messages = {}
    db = CDB()

    #Count number of messages sent by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has sent 2 messages on day "0", and 4 messages on day "5"
    while data != None:
        user = data[0]
        date = data[1]
        day = get_day(Date(date.month,date.day,date.year),days)
        if user in messages:
            if day in messages[user]:
                messages[user][day] += 1
            else:
                messages[user][day] = 1
        else:
            messages[user] = {}
            messages[user][day] = 1
        data = cur.fetchone()
    d = Data()
    d.set_data(messages)
    db.set_data(d)
    db.save("messages.db")
def gather_questions(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,createddate FROM mit.appuserquestion")
    data = cur.fetchone()
    questions = {}
    db = CDB()

    #Count number of questioin answered by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has answered 2 questions on day "0", and 4 questions on day "5"
    while data != None:
        user = data[0]
        date = data[1]
        day = get_day(Date(date.month,date.day,date.year),days)
        if user in questions:
            if day in questions[user]:
                questions[user][day] += 1
            else:
                questions[user][day] = 1
        else:
            questions[user] = {}
            questions[user][day] = 1
        data = cur.fetchone()
    d = Data()
    d.set_data(questions)
    db.set_data(d)
    db.save("questions.db")
def get_days():
    #Function to assign a mapping of Date to number of days since December 6, 2016.
    #Returns Mapping.
    days = 0
    days_map = {}
    current_day = Date(12,6,2016)
    end = Date(9,25,2017)
    days_map[current_day] = days
    while True:
        current_day = current_day.copy()
        current_day.tomorrow()
        days += 1
        days_map[current_day] = days
        if current_day == end:
            break
    return days_map
def gather_swipes(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,liked,lastseen FROM mit.apprecommendation")# WHERE createddate < '2017-08-25 00:00:00' AND createddate > '2017-08-01 00:00:00';")
    data = cur.fetchone()
    swipes = {}

    #Count number of users swiped by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has swiped on 2 other users on day "0", and 4 other users on day "5"
    while data != None:
        swipes = {}
        user = data[0]
        createddate = data[2]
        if swiped != 0:
            date = Date(createddate.month,createddate.day,createddate.year)
            day = get_day(date,days)
            if user in swipes:
                if day in swipes[user]:
                    swipes[user][day] += 1
                else:
                    swipes[user][day] = 1
            else:
                swipes[user] = {}
                swipes[user][day] = 1
        data = cur.fetchone()

    d = Data()
    d.set_data(swipes)
    db = CDB()
    db.set_data(d)
    db.save("swipes.db")
Exemplo n.º 22
0
def lifetime_report():
    """Lifetime report, all statistics"""
    if "user" in session:
        user = session["user"]
        date = Date()
        current_date = date.todays_date()
        total = random_data([x for x in range(9, 9999)], 1)
        total_players = random_data([x for x in range(59999, 99999)], 1)
        revenue = sum(random_data([x for x in range(9, 9999)], 12))
        sale = sum(random_data([x for x in range(9, 9999)], 12))
        event_data = [generate_buzz() for _ in range(5)]
        country = random_data(countries, 12)
        labels = [x.upper() for x in country]
        values = random_data([x for x in range(499, 14999)], 12)
        colors = [
            "#F7464A", "#46BFBD", "#FDB45C", "#FEDCBA",
            "#ABCDEF", "#DDDDDD", "#ABCABC", "#4169E1",
            "#C71585", "#FF4500", "#FEDCBA", "#46BFBD"
        ]

        return render_template('reports/lifetime_report.html', title="Lifetime Report | BestApp",
                               todays_date=current_date, username=user,
                               total=total, revenue=revenue, sale=sale,
                               max=17000, chart_=zip(values, labels, colors),
                               event_data=event_data, total_players=total_players)
    else:
        return redirect(url_for('login'))
Exemplo n.º 23
0
def main():
    bornBefore = Date(6, 1, 1995)  #date to be 21 or older
    date = promptAndExtractDate()
    while date is not None:
        if date <= bornBefore:
            print("Is at least 21 years of age: ", date)
        date = promptAndExtractDate()
    def create_date(self):

        system('cls')

        num_id = int(input("Enter the student's identification: "))
        pos = self.find_student(num_id)

        if pos != -1:

            number = self.generate_number_entry()
            student = self.students[pos]

            year = int(input("Enter the year of the date: "))
            mounth = int(input("Enter the mounth of the date: "))
            day = int(input("Enter the day of the date: "))

            new_date = Date(year, mounth, day)
            new_entry = Entry(number, new_date, student)

            self.entrys.append(new_entry)

            system('cls')
            print("The number of the entry is: ", number)

        else:
            print("ERROR - The student not exists")

        input()
Exemplo n.º 25
0
def main():
    today = Date()
    print(today)

    print('\nTesting setMonth()')
    today.setMonth(-4)
    print(today)
    today.setMonth(13)
    print(today)
    today.setMonth(4.5)
    print(today)
    today.setMonth(4)
    print(today)

    print('\nTesting setYear()')
    today.setYear(2014.5)
    print(today)
    today.setYear(1581)
    print(today)
    today.setYear(-2)
    print(today)
    today.setYear(2014)
    print(today)

    print('\nTesting setDay()')
    today.setDay(31)
    print(today)
    today.setDay(-1)
    print(today)
    today.setDay(15.3)
    print(today)
    today.setDay(14)
    print(today)
Exemplo n.º 26
0
def test_day_month_year_good(day, month, year):
    date = Date(1, 1, 1)
    date.day = day
    date.month = month
    date.year = year
    assert day == date.day
    assert month == date.month
    assert year == date.year
Exemplo n.º 27
0
def test_dey_month_year_bad1(day, month, year, err):
    d = Date(1, 2, 3)
    with pytest.raises(err):
        d.day = day
    with pytest.raises(err):
        d.month = month
    with pytest.raises(err):
        d.year = year
Exemplo n.º 28
0
def test_sub(date):
    """Tests whether the build-in sub method works for Date objects"""
    tester = Date('07 04 2020')
    assert tester
    assert date
    assert date - tester > 0
    assert date - tester == (datetime.date(datetime.now()) -
                             d(2020, 7, 4)).days
Exemplo n.º 29
0
def prev_month(start_date):
    cur_date = start_date
    while cur_date.numday > 7:
        cur_date = Date(cur_date.day, cur_date.month, cur_date.numday - 7,
                        cur_date.year)

    while start_date.month == cur_date.month:
        cur_date = cur_date.prev_date()

    backwards_days = (cur_date.numday % 7) - 1
    if backwards_days == -1: backwards_days = 6

    count_day = cur_date.day
    for count in range(0, backwards_days):
        count_day = Day.prev_day(count_day)

    return Date(count_day, cur_date.month, 1, cur_date.year)
Exemplo n.º 30
0
def promptAndExtractDate():
    print("Enter a birth date.")
    month = int(input("month (0 to quit): "))
    if month == 0:
        return None
    else:
        day = int(input("day: "))
        year = int(input("year: "))
        return Date(month, day, year)