Example #1
0
def insert_exercise_info(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'html.parser')

    # Extracts exercise name from website.
    name = soup.find(class_='page-title').get_text()

    # Extracts div with exercise info and puts into list.
    instructions_content = soup.find(class_='col-sm-6')
    instructions_list = instructions_content.findAll('p')
    prep = instructions_list[1].get_text()
    instruction = instructions_list[3].get_text()

    # Extracts video link
    video_link = instructions_content.findAll('source')
    video = video_link[0]['src']

    # To extract Main Target Muscles
    instructions_content_other = soup.find(class_='col-sm-6').next_sibling
    target_muscles_list = instructions_content_other.findAll('a')

    targets = ""

    for target in target_muscles_list:
        if "Muscles" in str(target):
            targets = target.text
            break
        # Break to stop at first iteration, as first value is main target muscles.

    print(name)
    print(prep)
    print(instruction)
    print(video)
    print(targets)
    print("")

    # Inserts extracted data into database.
    new_exercise = Exercise(name=str(name),
                            part="calves",
                            equipment="dumbbell",
                            prep=str(prep),
                            instruction=str(instruction),
                            video=str(video),
                            targets=str(targets))
    new_exercise.insert()


# insert_exercise_info("https://exrx.net/WeightExercises/Gastrocnemius/DBStandingCalfRaise")
# insert_exercise_info("https://exrx.net/WeightExercises/Gastrocnemius/DBSingleLegCalfRaise")
# insert_exercise_info("https://exrx.net/WeightExercises/Brachioradialis/CBReversePreacherCurl")
# insert_exercise_info("https://exrx.net/WeightExercises/Hamstrings/CBStraightLegDeadlift")
# insert_exercise_info("https://exrx.net/WeightExercises/Hamstrings/BBStraightLegDeadlift")
# insert_exercise_info("https://exrx.net/WeightExercises/Triceps/CBTriExt")
	def post(self):
		statusCode = 200
		emailAddress = self.request.get('emailAddress')
		logging.info(self.request.body)
		logging.info(json.loads(self.request.body))
		exerciseContents = json.loads(self.request.body)
		name = exerciseContents["name"]
		notes = exerciseContents['notes']
		multimedia = exerciseContents['multimedia']
		description = exerciseContents['description']
		tags = exerciseContents['tags']
		exercise = Exercise(name=name, notes=notes, multimedia=multimedia, description=description, tags=tags, createdBy=emailAddress)
		exercise.put()
		self.response.write(json.dumps({'statusCode': statusCode}))
Example #3
0
def get_exercise_from_database(db_file, _id=0, _name="", _link="", _desc=""):
    if _id < 0:
        ex = Exercise(_id=_id,
                      _name="Круг " + str(-_id),
                      _temp=".",
                      _repeat=0,
                      _link=_link,
                      _desc=_desc)
        return ex
    if _name[:5] == "Круг ":
        ex = Exercise(_id=-int(_name[5:]),
                      _name=_name + str(-_id),
                      _temp=".",
                      _repeat=0,
                      _link=_link,
                      _desc=_desc)
        return ex
    connection = create_connection(db_file)
    with connection:
        sql = ''' SELECT * FROM Exercises'''
        cnt = 0
        sql += " WHERE "
        if _id > 0:
            sql += 'id = "' + str(_id) + '"'
            cnt += 1
        if _name:
            if cnt > 0:
                sql += " AND "
            sql += 'name = "' + str(_name) + '"'
            cnt += 1
        if _desc:
            if cnt > 0:
                sql += " AND "
            sql += 'description = "' + str(_desc) + '"'
            cnt += 1
        if _link:
            if cnt > 0:
                sql += " AND "
            sql += 'link = "' + str(_link) + '"'
            cnt += 1
        cur = connection.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        if rows:
            row = ExercisePattern(_tuple=rows[0])
        else:
            row = Exercise()
        return row
    def _get_exercise_info(self):
        exercise_box = self.soup.find(id='meal-plan-table')

        try:
            list_ = exercise_box.find('ul')
        except:
            # Most likely a rest day. Can't get info!
            return

        for list_item in list_.find_all('a'):
            if not len(list_item.text):
                continue

            exercise_name = self._parse_name(list_item.text)
            exerse = Exercise(exercise_name)
            self.exercise_list.append(exerse)

        i = 0
        for desc in list_.find_all('span', class_='mpt-content content'):
            self.exercise_list[i].set_description(desc.text.strip())

            sets = self._parse_sets(self.exercise_list[i].desc)
            reps = self._parse_reps(desc.text)
            # print "sets: %s reps: %s" % (sets, reps)

            self.exercise_list[i].set_sets(sets)
            self.exercise_list[i].set_reps(reps)

            i += 1
Example #5
0
def read_plans_from_database(db_file, users, exercises, all=False):
    connection = create_connection(db_file)
    with connection:
        cur = connection.cursor()
        sql = "SELECT * FROM Plans"
        if not all:
            sql += " WHERE changed = TRUE"
        cur.execute(sql)
        rows = cur.fetchall()
        some_array = []
        for row in rows:
            print(row)
            user_id = row[1]
            train_num = row[2]
            exer_num = row[3]
            pattern = exercises[row[4] + 1]
            ex = Exercise(_name=pattern.name,
                          _link=pattern.link,
                          _desc=pattern.desc,
                          _temp=row[5],
                          _repeat=row[6])
            while len(users[user_id].trainings) <= train_num:
                users[user_id].trainings.append(Training())
            if len(users[user_id].trainings[train_num].exercises) <= exer_num:
                users[user_id].trainings[train_num].exercises.append(ex)
            else:
                users[user_id].trainings[train_num].exercises[exer_num] = ex
            new_sql = "UPDATE Plans SET changed = True WHERE id = " + str(
                row[0])
            cur.execute(new_sql)
Example #6
0
def get_exercise_from_database(db_file, _id=-1, _name="", _link="", _desc=""):
    connection = create_connection(db_file)
    with connection:
        sql = ''' SELECT * FROM Exercises'''
        cnt = 0
        sql += " WHERE "
        if _id >= 0:
            sql += 'id = "' + str(_id) + '"'
            cnt += 1
        if _name:
            if cnt > 0:
                sql += " AND "
            sql += 'name = "' + str(_name) + '"'
            cnt += 1
        if _desc:
            if cnt > 0:
                sql += " AND "
            sql += 'description = "' + str(_desc) + '"'
            cnt += 1
        if _link:
            if cnt > 0:
                sql += " AND "
            sql += 'link = "' + str(_link) + '"'
            cnt += 1
        print("Get exercise : " + sql)
        cur = connection.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        if rows:
            row = ExercisePattern(_tuple=rows[0])
        else:
            row = Exercise()
        return row
Example #7
0
 def generate(self):
     """
     Generation task
     :return:
     """
     for row_index in range(0, self.COUNT_ROW):
         columns = []
         for column_index in range(0, self.COUNT_COLUMN):
             tmp_exercise = Exercise(self.get_first(row_index),
                                     self.get_second(),
                                     self.get_operation(column_index))
             while self.check_repeat(tmp_exercise, column_index):
                 tmp_exercise = Exercise(self.get_first(row_index),
                                         self.get_second(),
                                         self.get_operation(column_index))
             columns.append(tmp_exercise)
         self.rows.append(columns)
Example #8
0
def get_user_plans_from_database(db_file, user, user_id):
    connection = create_connection(db_file)
    with connection:
        sql = ''' SELECT * FROM Plans WHERE user_id = ''' + str(user_id)
        cur = connection.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        for row in rows:
            tr_id = row[2]
            ex_id = row[3]
            while len(user.trainings) <= tr_id:
                user.trainings.append(Training())
            while len(user.trainings[tr_id].exercises) < ex_id:
                user.trainings[tr_id].exercises.adppend(Exercise())
            new_ex_pattern = get_exercise_from_database(db_file, _id=row[4])
            new_ex = Exercise(pattern=new_ex_pattern,
                              _temp=row[5],
                              _repeat=row[6])
            if len(user.trainings[tr_id].exercises) == ex_id:
                user.trainings[tr_id].exercises.append(new_ex)
            else:
                user.trainings[tr_id].exercises[ex_id] = new_ex
	def get(self):
		statusCode = 200
		tags = ''
		for exercise in Exercise.query():
			eTags = exercise.tags
			for tag in exercise.tags.split(","):
				if tag not in tags:
					if tags == '':
						tags = tag
					else:
						tags = tags + "," + tag
				if tag == 'None':
					logging.info(eTags)
					eTags = eTags.replace('None,','')
					eTags = eTags.replace(',None','')
					eTags = eTags.replace('None','')
					logging.info(eTags)
					exercise.tags = eTags
					exercise.put()
		self.response.write(json.dumps({'statusCode': statusCode, 'tags': tags}))
Example #10
0
def readFile():
    # open notes.txt file
    with open("res/notes.txt", "r") as f:
        days = []
        skip_first = False
        list_ex = []
        line = f.readline().rstrip('\n')
        while 1:
            if 'new' in line:
                print('\033[94m' + "New day!" + "\033[0m")
                if skip_first is True:
                    day = Day(line, list_ex)
                    days.append(day)
                skip_first = True
                line = f.readline().rstrip('\n')
            # ex name
            if ':' in line:
                reps = 0
                ex_time = line.split(":")
                ex = Exercise(ex_time[0], ex_time[1])
                while 1:
                    line = f.readline().rstrip('\n')
                    # Set
                    if ('[' in line) & (']' in line):
                        reps = reps + 1
                        set_info = re.split('x |- ', line)
                        slice_object = slice(4, -1)
                        # Set has no weight
                        if len(set_info) == 2:
                            sets = Set(int(set_info[0][slice_object]),
                                       int(set_info[1]))
                        else:
                            sets = Set(int(set_info[0][slice_object]),
                                       int(set_info[2]), int(set_info[1]))
                        ex.addSet(sets)
                    # save exercise
                    else:
                        ex.setNReps(reps)
                        list_ex.append(ex)
                        break
            if line == '':
                break
    f.close()
    return days
Example #11
0
    def __init__(self, conf, exc_file = ""):
        self.conf = conf
        self.exercise_file = exc_file
        
        logging.info("Loading exercise "+exc_file)
        e=Exercise(exc_file)
        
        # Find the FIR mentioned by the exercise file
        fir_list = FIR.load_firs(os.path.dirname(exc_file))
        try: fir = [fir for fir in fir_list if fir.name==e.fir][0]
        except:
            logging.critical("Unable to load FIR file for "+str(exc_file))
            raise
            return        
        self.fir        = fir
        Aircraft.fir    = fir  # Rather than passing globals
        Route.fir       = fir
        TLPV.fir        = fir
        
        self.sector     = e.sector
        # TODO wind and qnh should be properties of the atmosphere object
        # and should be variables dependent on location and height in the case of wind
        self.wind       = [e.wind_knots, e.wind_azimuth]
        # We have set somewhere else a fixed seed so that squawks are reproducible
        # but we want the qnh to be different in each exercise, so we use getstate and setstate
        st = random.getstate()
        random.seed()
        self.qnh        = random.gauss(1013.2, 8)
        self.qnh_var    = random.gauss(0, QNH_STD_VAR)  # Variation in mB per second.
                                                # Should not be much more than 1mB per 10minutes
        random.setstate(st)
        
        # Initializes time
        self.cont = True  # Marks when the main loop should exit
        t = datetime.datetime.today()
        self.t = t.replace(t.year, t.month, t.day,
                           int(e.start_time[0:2]), int(e.start_time[3:5]), 0, 0)
        self.last_update = self.t - datetime.timedelta(seconds=5) # Copy the datetimeobject
                      
        fact_t = self.fact_t = 1.0
        self.paused = False

        self.tlpv = tlpv = TLPV.TLPV(exc_file)
        
        # Create the aircraft for each of the flights in the exercise
        self.flights = []
        logging.debug("Loading aircraft")
        for ef in e.flights.values():  # Exercise flights
            
            # TODO Because the current exercise format cannot distiguish between
            # overflights and departures first we create them all as overflights
             
            eto = datetime.datetime.today()
            eto = eto.replace(hour=int(ef.eto[:2]), minute=int(ef.eto[2:4]), second=int(ef.eto[4:6]))
            logging.debug("Loading %s"%ef.callsign)
            try:
                a = Aircraft.Aircraft(ef.callsign, ef.type, ef.adep, ef.ades,
                                      float(ef.cfl), float(ef.rfl), ef.route,
                                      next_wp = ef.fix, next_wp_eto = eto,
                                      wake_hint = ef.wtc)
            except:
                logging.warning("Unable to load "+ef.callsign, exc_info=True)
                continue
            
            a.lvl = int(ef.firstlevel)
            
            # TODO We need to know which of the flights are true departures. We assume that 
            # if the aircraft departs from an airfield local to the FIR,
            # the EOBT is the estimate to the first point in the route
            # We substitute the overflight (created using next_wp_eto) with a departure
            # (created using an EOBT)
            if a.adep in fir.aerodromes.keys():
                eobt = a.route[0].eto
                a = Aircraft.Aircraft(a.callsign, a.type, a.adep, a.ades,
                                       a.cfl, a.rfl, a.route, eobt = eobt,
                                       wake_hint=a.wake_hint)
                if not fir.auto_departures[self.sector] \
                  and a.adep in fir.release_required_ads[self.sector]:
                    a.auto_depart = False
            
            self.flights.append(a)
            
            # Creates new flight plans from the loaded aircraft
            if a.eobt: ecl = a.rfl  # If it's a departure
            else: ecl = a.cfl
            fp = tlpv.create_fp(ef.callsign, ef.type, ef.adep, ef.ades,
                                  float(ef.rfl), ecl, a.route, eobt = a.eobt,
                                  next_wp = a.next_wp, next_wp_eto = a.next_wp_eto)
            a.squawk = fp.squawk  # Set the aircraft's transponder to what the flight plan says
            a.fs_print_t = fp.fs_print_t
            fp.wake  = ef.wtc     # Keep the WTC in the exercise file, even if wrong
            fp.filed_tas = int(ef.tas)
            
        tlpv.start()
            
        self.protocol_factory=GTA_Protocol_Factory(self, fir.file, self.sector, self.flights)
        
        self.pseudopilots = []  # List of connected pseudopilot clients
        self.controllers  = []  # List of connected controller clients
Example #12
0
def generate_workout():

    workout_list = []
    workout_list.clear()

    # Get JSON values from Post Request sent from Workout.js.
    data = request.get_json()
    main = data.get("main")
    secondary = data.get("secondary")
    equip = data.get("equip")
    # Select workout by random PK(ID) where name=main and secondary. Main=4 Exercises. Secondary=2 Exercises.
    while len(workout_list) < 4:
        if (main == "shoulders"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(1, 15)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(1, 15)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
            # checkGenerate(lift, workout_list, rand_num, pk_list)
        elif (main == "biceps"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(16, 27)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(16, 27)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "triceps"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(28, 40)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(28, 40)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "back"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(41, 55)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(41, 55)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "chest"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(56, 70)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(56, 70)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "quads"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(71, 83)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(71, 83)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "hams"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(84, 94)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(84, 94)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "forearms"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(95, 100)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(95, 100)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
        elif (main == "calves"):
            if (equip != "none"):
                while (len(workout_list) < 3):
                    rand_num = randint(101, 106)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
            rand_num = randint(101, 106)
            lift = Exercise.exercise_by_name(rand_num, main)
            if lift not in workout_list and lift != None:
                workout_list.append(lift)
    if len(workout_list) >= 4:
        while len(workout_list) < 6:
            if (secondary == "shoulders"):
                if (equip != "none"):
                    rand_num = randint(1, 15)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(1, 15)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "biceps"):
                if (equip != "none"):
                    rand_num = randint(16, 27)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(16, 27)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "triceps"):
                if (equip != "none"):
                    rand_num = randint(28, 40)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(28, 40)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "back"):
                if (equip != "none"):
                    rand_num = randint(41, 55)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(41, 55)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "chest"):
                if (equip != "none"):
                    rand_num = randint(56, 70)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(56, 70)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "quads"):
                if (equip != "none"):
                    rand_num = randint(71, 83)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(71, 83)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "hams"):
                if (equip != "none"):
                    rand_num = randint(84, 94)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(84, 94)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "forearms"):
                if (equip != "none"):
                    rand_num = randint(95, 100)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(95, 100)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)
            elif (secondary == "calves"):
                if (equip != "none"):
                    rand_num = randint(101, 106)
                    lift = Exercise.exercise_by_name_and_equip(
                        rand_num, main, equip)
                    if lift not in workout_list and lift != None:
                        workout_list.append(lift)
                rand_num = randint(101, 106)
                lift = Exercise.exercise_by_name(rand_num, secondary)
                if lift not in workout_list and lift != None:
                    workout_list.append(lift)

    print(workout_list)
    return jsonify({"workout": workout_list})
	def get(self):
		statusCode = 200
		exercises = []
		for exercise in Exercise.query():
			exercises.append(exercise.JSONOutput())
		self.response.write(json.dumps({'statusCode': statusCode, 'exercises': exercises}))
Example #14
0
    tank = Tank()
    tank.start()
    time.sleep(_wait_time)

    logger.info("Start Coffee machine")
    coffee = SmartCoffee()
    coffee.start()
    time.sleep(_wait_time)

    logger.info("Start Newscatcher")
    newscatcher = Newscatcher()
    newscatcher.start()
    time.sleep(_wait_time)

    logger.info("Start Exercise")
    exercise = Exercise()
    exercise.start()
    time.sleep(_wait_time)

    #https://github.com/dbader/schedule

    schedule.every(23).minutes.do(checkWaschingMachine)
    schedule.every(1).minutes.do(checkBath)
    schedule.every(30).minutes.do(bathShowerUpdate)

    schedule.every().hour.at("00:00").do(hourAnnounce)
    schedule.every().hour.at("00:42").do(radiationCheck)
    schedule.every().hour.at("00:23").do(particulateMatterCheck)

    schedule.every().day.at("03:23").do(stopme)
Example #15
0
def view_exercises():
    exercise_list = Exercise.view_exercises()
    return jsonify({"exercises": exercise_list})
Example #16
0
class TestExercise(TestCase):

    def setUp(self):
        self.s = Exercise()
        self.sub = Exercise(6, 1, 'sub')
        self.sub1 = Exercise(1, 6, 'sub')
        self.mul = Exercise(2, 6, 'mul')
        self.div = Exercise(2, 6, 'div')

    def test_exception_in_constructor(self):
        with self.assertRaises(Exception):
            Exercise(operation='test')

    def test_type_of_property(self):
        self.assertTrue(type(self.s.LIST_OPERATIONS) is tuple, 'obj.LIST_OPERATIONS ot type tuple')
        self.assertTrue(type(self.s.DEFAULT_OPERATION) is str, 'obj.DEFAULT_OPERATION ot type str')
        self.assertTrue(type(self.s.OUT_FORMAT_LIST) is tuple, 'obj.DEFAULT_OPERATION ot type tuple')
        self.assertTrue(type(self.s.singleOperation) is dict, 'obj.singleOperation ot type dict')
        self.assertTrue(type(self.s.create) is bool, 'obj.create ot type dict')
        self.assertTrue(type(self.s.operation) is str, 'obj.operation ot type str')
        self.assertTrue(type(self.s.a) is int, 'obj.a of type int')
        self.assertTrue(type(self.s.a_str) is str, 'obj.a_str of type str')
        self.assertTrue(type(self.s.b) is int, 'obj.b of type int')
        self.assertTrue(type(self.s.b_str) is str, 'obj.b_str of type str')
        self.assertTrue(type(self.s.result) is int, 'obj.result of type int')
        self.assertTrue(type(self.s.result_str) is str, 'obj.result_str of type str')

    def test_constructor(self):
        self.assertIsInstance(self.s, Exercise, 'Creation by default Exercise')
        self.assertEqual(self.s.a, 0, 'obj.a by default equal 0')
        self.assertEqual(self.s.b, 0, 'obj.b by default equal 0')
        self.assertEqual(self.s.result, 0, 'obj.result by default equal 0')
        self.assertEqual(self.s.a_str, ' 0 ', 'obj.a by default equal " 0 "')
        self.assertEqual(self.s.b_str, ' 0 ', 'obj.b by default equal " 0 "')
        self.assertEqual(self.s.result_str, ' 0 ', 'obj.result_str by default equal " 0 "')
        self.assertEqual(self.s.operation, 'sum', 'obj.operation_str by default equal "sum"')
        self.assertEqual(self.s.create, True, 'obj.create by default equal True')

    def test_operation_mul(self):
        self.assertIsInstance(self.mul, Exercise, 'Creation by default Exercise')
        self.assertEqual(self.mul.a, 2, 'obj.a by default equal 2')
        self.assertEqual(self.mul.b, 6, 'obj.b by default equal 6')
        self.assertEqual(self.mul.result, 12, 'obj.result by default equal 12')
        self.assertEqual(self.mul.a_str, ' 2 ', 'obj.a by default equal " 2 "')
        self.assertEqual(self.mul.b_str, ' 6 ', 'obj.b by default equal " 6 "')
        self.assertEqual(self.mul.result_str, '12 ', 'obj.result_str by default equal " 12"')
        self.assertEqual(self.mul.operation, 'mul', 'obj.operation_str by default equal "mul"')
        self.assertEqual(self.mul.create, True, 'obj.create by default equal True')

    def test_operation_div(self):
        self.assertIsInstance(self.div, Exercise, 'Creation by default Exercise')
        self.assertEqual(self.div.a, 12, 'obj.a by default equal 2')
        self.assertEqual(self.div.b, 6, 'obj.b by default equal 6')
        self.assertEqual(self.div.result, 2, 'obj.result by default equal 12')
        self.assertEqual(self.div.a_str, '12 ', 'obj.a by default equal "12 "')
        self.assertEqual(self.div.b_str, ' 6 ', 'obj.b by default equal " 6 "')
        self.assertEqual(self.div.result_str, ' 2 ', 'obj.result_str by default equal " 2 "')
        self.assertEqual(self.div.operation, 'div', 'obj.operation_str by default equal "div"')
        self.assertEqual(self.div.create, True, 'obj.create by default equal True')

    def test_operation_sub(self):
        self.assertIsInstance(self.sub, Exercise, 'Creation by default Exercise')
        self.assertEqual(self.sub.a, 6, 'obj.a by default equal 6')
        self.assertEqual(self.sub.b, 1, 'obj.b by default equal 1')
        self.assertEqual(self.sub.result, 5, 'obj.result by default equal 5')
        self.assertEqual(self.sub.a_str, ' 6 ', 'obj.a by default equal " 6 "')
        self.assertEqual(self.sub.b_str, ' 1 ', 'obj.b by default equal " 1 "')
        self.assertEqual(self.sub.result_str, ' 5 ', 'obj.result_str by default equal " 5 "')
        self.assertEqual(self.sub.operation, 'sub', 'obj.operation_str by default equal "sub"')
        self.assertEqual(self.sub.create, True, 'obj.create by default equal True')

    def test_operation_sub1(self):
        self.assertIsInstance(self.sub, Exercise, 'Creation by default Exercise')
        self.assertEqual(self.sub1.a, 6, 'obj.a by default equal 6')
        self.assertEqual(self.sub1.b, 6, 'obj.b by default equal 6')
        self.assertEqual(self.sub1.result, 0, 'obj.result by default equal 0')
        self.assertEqual(self.sub1.a_str, ' 6 ', 'obj.a by default equal " 6 "')
        self.assertEqual(self.sub1.b_str, ' 6 ', 'obj.b by default equal " 6 "')
        self.assertEqual(self.sub1.result_str, ' 0 ', 'obj.result_str by default equal " 0 "')
        self.assertEqual(self.sub1.operation, 'sub', 'obj.operation_str by default equal "sub"')
        self.assertEqual(self.sub1.create, True, 'obj.create by default equal True')

    def test_for_out(self):
        self.assertEqual(self.s.for_out(), '  0  +  0  =   ', 'obj.for_out() returned "'+self.s.for_out()+'"')
        self.assertEqual(self.s.for_out(0), '  0  +  0  = 0 ', 'obj.for_out(0) returned "'+self.s.for_out(0)+'"')
        self.assertEqual(self.s.for_out(2), '  0  +     = 0 ', 'obj.for_out(2) returned "'+self.s.for_out(2)+'"')
        self.assertEqual(self.s.for_out(3), '     +  0  = 0 ', 'obj.for_out(3) returned "'+self.s.for_out(3)+'"')
        self.assertEqual(self.s.for_out(4), '  0     0  = 0 ', 'obj.for_out(4) returned "'+self.s.for_out(4)+'"')
        self.assertEqual(self.sub.for_out(), '  6  -  1  =   ', 'obj.for_out() returned "'+self.sub.for_out()+'"')
        self.assertEqual(self.sub.for_out(0), '  6  -  1  = 5 ', 'obj.for_out(0) returned "'+self.sub.for_out(0)+'"')
        self.assertEqual(self.sub.for_out(2), '  6  -     = 5 ', 'obj.for_out(2) returned "'+self.sub.for_out(2)+'"')
        self.assertEqual(self.sub.for_out(3), '     -  1  = 5 ', 'obj.for_out(3) returned "'+self.sub.for_out(3)+'"')
        self.assertEqual(self.sub.for_out(4), '  6     1  = 5 ', 'obj.for_out(4) returned "'+self.sub.for_out(4)+'"')
        self.assertEqual(self.sub1.for_out(), '  6  -  6  =   ', 'obj.for_out() returned "'+self.sub1.for_out()+'"')
        self.assertEqual(self.sub1.for_out(0), '  6  -  6  = 0 ', 'obj.for_out(0) returned "'+self.sub1.for_out(0)+'"')
        self.assertEqual(self.sub1.for_out(2), '  6  -     = 0 ', 'obj.for_out(2) returned "'+self.sub1.for_out(2)+'"')
        self.assertEqual(self.sub1.for_out(3), '     -  6  = 0 ', 'obj.for_out(3) returned "'+self.sub1.for_out(3)+'"')
        self.assertEqual(self.sub1.for_out(4), '  6     6  = 0 ', 'obj.for_out(4) returned "'+self.sub1.for_out(4)+'"')
        self.assertEqual(self.mul.for_out(), '  2  ' + u'\xd7' + '  6  =   ', 'obj.for_out() returned "'
                         + self.mul.for_out()+'"')
        self.assertEqual(self.mul.for_out(0), '  2  ' + u'\xd7' + '  6  =12 ', 'obj.for_out(0) returned "'
                         + self.mul.for_out(0)+'"')
        self.assertEqual(self.mul.for_out(2), '  2  ' + u'\xd7' + '     =12 ', 'obj.for_out(2) returned "'
                         + self.mul.for_out(2)+'"')
        self.assertEqual(self.mul.for_out(3), '     ' + u'\xd7' + '  6  =12 ', 'obj.for_out(3) returned "'
                         + self.mul.for_out(3)+'"')
        self.assertEqual(self.mul.for_out(4), '  2     6  =12 ', 'obj.for_out(4) returned "'
                         + self.mul.for_out(4)+'"')
        self.assertEqual(self.div.for_out(), ' 12  ' + u'\xf7' + '  6  =   ', 'obj.for_out() returned "'
                         + self.div.for_out() + '"')
        self.assertEqual(self.div.for_out(0), ' 12  ' + u'\xf7' + '  6  = 2 ', 'obj.for_out(0) returned "'
                         + self.div.for_out(0) + '"')
        self.assertEqual(self.div.for_out(2), ' 12  ' + u'\xf7' + '     = 2 ', 'obj.for_out(2) returned "'
                         + self.div.for_out(2) + '"')
        self.assertEqual(self.div.for_out(3), '     ' + u'\xf7' + '  6  = 2 ', 'obj.for_out(3) returned "'
                         + self.div.for_out(3) + '"')
        self.assertEqual(self.div.for_out(4), ' 12     6  = 2 ', 'obj.for_out(4) returned "'
                         + self.div.for_out(4) + '"')
Example #17
0
from SceneManager import SceneManager
from Camera import Camera
from Exercise import Exercise
from Menu import Menu



# Define the managers, which handle the inputs and the scenes. This needs to be done before mostly everything
sceneManager = SceneManager()

# Create the necessary inputs
camera = Camera()


exerciseScene = Exercise([], sceneManager, camera)
menuScene = Menu(sceneManager, camera)
sceneManager.addScene(exerciseScene, "Exercise")
sceneManager.addScene(menuScene, "Menu")
sceneManager.setActiveScene("Exercise")


# Main loop
while True:
    sceneManager.update()
Example #18
0
 def generateData(self):
     return Exercise().generate_exercise(5)
Example #19
0
 def loadData(self):
     return Exercise().import_exercise(self.filePath)
Example #20
0
    tank = Tank()
    tank.start()
    time.sleep(_wait_time)

    logger.info("Start Coffee machine")
    coffee = SmartCoffee()
    coffee.start()
    time.sleep(_wait_time)

    logger.info("Start Newscatcher")
    newscatcher = Newscatcher()
    newscatcher.start()
    time.sleep(_wait_time)

    logger.info("Start Exercise")
    exercise = Exercise()
    exercise.start()
    time.sleep(_wait_time)

    #https://github.com/dbader/schedule

    schedule.every(23).minutes.do(checkWaschingMachine)
    schedule.every( 1).minutes.do(checkBath)
    schedule.every(30).minutes.do(bathShowerUpdate)

    schedule.every().hour.at("00:00").do(hourAnnounce)
    schedule.every().hour.at("00:42").do(radiationCheck)
    schedule.every().hour.at("00:23").do(particulateMatterCheck)

    schedule.every().day.at("03:23").do(stopme)
Example #21
0
 def setUp(self):
     self.s = Exercise()
     self.sub = Exercise(6, 1, 'sub')
     self.sub1 = Exercise(1, 6, 'sub')
     self.mul = Exercise(2, 6, 'mul')
     self.div = Exercise(2, 6, 'div')
Example #22
0
 def test_exception_in_constructor(self):
     with self.assertRaises(Exception):
         Exercise(operation='test')