Ejemplo n.º 1
0
def test_banchemark_15():
    current_setup = "3-15"
    calculation.mongo_find_all_active_nodes = MagicMock(
        return_value=db_gen(15))
    job = {
        'requirements': {
            "cpu": 1,
            "memory": 100,
        },
        "id": 1,
        "image_runtime": "docker"
    }
    for i in range(100):
        app = MagicMock()
        app.logger.info = lambda x: None
        start = time.time()
        res, mes = calculation.calculate(app, job)
        if res != "positive":
            raise Exception()
        stop = time.time()
        overhead = stop - start
        overhead *= 1000
        results.append([i, "cluster", overhead, current_setup])

    print_csv()
Ejemplo n.º 2
0
def start_calc(job_id, job):
    # i = celeryapp.control.inspect()
    # print(i)

    scheduling_status, scheduling_result = calculate(job_id, job)
    print(scheduling_result)
    if scheduling_status == 'negative':
        mongo_update_job_status(job_id, scheduling_result)
    else:
        cluster_id = scheduling_result.get('_id')
        #mongo_update_job_status_and_cluster(job_id, 'CLUSTER_SCHEDULED', cluster_id)
        manager_request(scheduling_result, job_id, job, replicas=1)  # scheduling_result is a target cluster
Ejemplo n.º 3
0
def start_calc_deploy(job, job_id, instance_num):
    # i = celeryapp.control.inspect()
    # print(i)
    app.logger.info("App.logger.info Received Task")
    print("print Received Task")

    scheduling_status, scheduling_result = calculate(
        app, job)  # scheduling_result can be a node object

    if scheduling_status == 'negative':
        app.logger.info('No active node found to schedule this job.')
    else:
        app.logger.info('Chosen Node: {0}'.format(scheduling_result))
        manager_request(app, scheduling_result, job, job_id, instance_num)
Ejemplo n.º 4
0
def main():
    cli_headers.print_program_title()

    try:
        result_months = calculation.calculate(
            collect_input(validation.Rules.HOUSE_COST),
            collect_input(validation.Rules.DOWN_PAYMENT_PERCENT),
            collect_input(validation.Rules.SAVINGS),
            collect_input(validation.Rules.INTEREST_ON_SAVINGS),
            collect_input(validation.Rules.SALARY),
            collect_input(validation.Rules.SALARY_PERCENT_SAVED),
        )
    except OverflowError as e:
        cli_headers.print_with_borders(e)
    else:
        cli_headers.print_months_as_years_and_months(result_months)
Ejemplo n.º 5
0
    def when_calculate_button_clicked(self):
        if not self.are_field_inputs_valid():
            self.result_label.setText('Invalid inputs')
            return

        self._create_fields_as_floats_from_text()

        try:
            result_months = calculation.calculate(
                self.house_cost, self.down_payment_percent,
                self.savings, self.interest_on_savings,
                self.salary, self.salary_percent_saved
            )
        except OverflowError:
            self.result_label.setText("Error: Overflow")
            return

        formatted_result = f"{result_months//12} years, {result_months%12} months"
        self.result_label.setText(formatted_result)
Ejemplo n.º 6
0
 def test_calculate2(self):
     actual = calculate([9, 1, 5, 3, 3, 3, 2, 9, 0])
     expected = {
         'mean':
         [[4.666666666666667, 4.333333333333333, 2.6666666666666665],
          [5.0, 3.0, 3.6666666666666665], 3.888888888888889],
         'variance':
         [[9.555555555555555, 11.555555555555557, 4.222222222222222],
          [10.666666666666666, 0.0, 14.888888888888891], 9.209876543209875],
         'standard deviation':
         [[3.0912061651652345, 3.39934634239519, 2.0548046676563256],
          [3.265986323710904, 0.0, 3.8586123009300755], 3.0347778408328137],
         'max': [[9, 9, 5], [9, 3, 9], 9],
         'min': [[2, 1, 0], [1, 3, 0], 0],
         'sum': [[14, 13, 8], [15, 9, 11], 35]
     }
     self.assertAlmostEqual(
         actual, expected,
         "Expected different output when calling 'calculate()' with '[9,1,5,3,3,3,2,9,0]'"
     )
Ejemplo n.º 7
0
def test_banchemark_9():
    current_setup = "9-5"
    calculation.mongo_find_all_active_clusters = MagicMock(return_value=db_gen(9))
    job = {
        'requirements': {
            "cpu": 1,
            "memory": 100,
        },
        "id": 1
    }
    for i in range(100):
        start = time.time()
        res, mes = calculation.calculate("1", job)
        if res != "positive":
            raise Exception()
        stop = time.time()
        overhead = stop - start
        overhead *= 1000
        results.append([i, "root", overhead, current_setup])

    print_csv()
Ejemplo n.º 8
0
 def test_calculate(self):
     actual = calculate([2, 6, 2, 8, 4, 0, 1, 5, 7])
     expected = {
         'mean': [[3.6666666666666665, 5.0, 3.0],
                  [3.3333333333333335, 4.0, 4.333333333333333],
                  3.888888888888889],
         'variance':
         [[9.555555555555557, 0.6666666666666666, 8.666666666666666],
          [3.555555555555556, 10.666666666666666, 6.222222222222221],
          6.987654320987654],
         'standard deviation':
         [[3.091206165165235, 0.816496580927726, 2.943920288775949],
          [1.8856180831641267, 3.265986323710904, 2.494438257849294],
          2.6434171674156266],
         'max': [[8, 6, 7], [6, 8, 7], 8],
         'min': [[1, 4, 0], [2, 0, 1], 0],
         'sum': [[11, 15, 9], [10, 12, 13], 35]
     }
     self.assertAlmostEqual(
         actual, expected,
         "Expected different output when calling 'calculate()' with '[2,6,2,8,4,0,1,5,7]'"
     )
Ejemplo n.º 9
0
def formdata():
    global studentNum
    global facultyNum
    global studentResults
    global facultyResults
    global studentInfectious
    global facultyInfectious

    if request.method == 'POST':
        studentNum = None
        facultyNum = None
        studentResults = None
        facultyResults = None
        studentInfectious = None
        facultyInfectious = None

        content = request.data.decode()
        content = json.loads(content)

        numFaculty = content['numFaculty']
        numStudents = content['numStudents']
        numSessions = content['numSessions']
        durationSessions = content['durationSessions']
        classFloorArea = content['classFloorArea']
        classHeight = content['classHeight']
        county = content['county']
        state = content['state']
        infectionRate = content['infectionRate']

        studentNum, facultyNum, studentResults, facultyResults, facultyInfectious, studentInfectious = calculate(
            numFaculty, numStudents, numSessions, durationSessions,
            classFloorArea, classHeight, county, state, infectionRate)
        # while studentResults is None or facultyResults is None or studentNum is None or facultyNum is None:
        #     pass

        return jsonify({})
    else:
        while studentResults is None or facultyResults is None or studentNum is None or facultyNum is None:
            pass

        results = {
            'percentFaculty': facultyNum,
            'percentStudent': studentNum,
            'probFaculty5': facultyResults['fac_quants_05'],
            'probFaculty25': facultyResults['fac_quants_25'],
            'probFaculty50': facultyResults['fac_quants_50'],
            'probFaculty75': facultyResults['fac_quants_75'],
            'probFaculty95': facultyResults['fac_quants_95'],
            'probStudent5': studentResults['student_quants_05'],
            'probStudent25': studentResults['student_quants_25'],
            'probStudent50': studentResults['student_quants_50'],
            'probStudent75': studentResults['student_quants_75'],
            'probStudent95': studentResults['student_quants_95'],
            'facultyInfectious': facultyInfectious,
            'studentInfectious': studentInfectious
        }
        return jsonify(results)
Ejemplo n.º 10
0
# This entrypoint file to be used in development. Start by reading README.md
from calculation import calculate
from unittest import main

results = calculate([0, 1, 2, 3, 4, 5, 6, 7, 8])

for key, value in results.items():
    print('{} : {}'.format(key, value))

main(module='test_calculation', exit=False)
Ejemplo n.º 11
0
        writer = csv.writer(out)

        #writing header for csv
        writer.writerow([
            "Matchday", "Date", "HomeTeam", "AwayTeam", "HomeWin", "Draw",
            "HomeLose", "ActualResult"
        ])

        #read the header
        next(inp)

        for x in csv.reader(inp):
            row = utils.split_list(x, ";")

            home_team = row[2]
            away_team = row[3]
            date = row[1]
            season = utils.get_season(row[1])

            utils.generate_data_for_calculation(home_team, away_team,
                                                utils.get_year(date))

            result = calculation.calculate(home_team, away_team, season)

            writer.writerow([
                row[0], date, home_team, away_team, result[0], result[1],
                result[2], row[4]
            ])

    except IOError as err:
        print("IO Error Number", err.errno, "[", err.strerror, "]")
Ejemplo n.º 12
0
print("BEGINNER")

while True:
    import random
    a = randint(0, 9)
    b = randint(1, 9)
    if point < 5:
        equation = list('+')
    elif point == 5:
        print("ADVANCED")
        equation.append('-')
        equation.append('*')
        equation.append('/')
    c = random.choice(equation)
    d = randint(-1, 1)
    z = calculate(a, b, c)
    print(f"{a} {c} {b} = {z+d}")
    user_answer = input("Is this equation true or false? (T/F): ")
    if d == 0:
        if user_answer == "T":
            print("You are correct!")
            point = point + 1
        else:
            print("You are wrong!")
    else:
        if user_answer == "T":
            print("You are wrong!")
        else:
            print("You are correct!")
            point = point + 1
    print("Your point is: ", point)
Ejemplo n.º 13
0
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import datetime as d
from calculation import calculate
import time
from pathlib import Path


# Get execution time of the program
start_time = time.time()

# Statistics Calculator for Issue Objects
calculator = calculate()

# reload(sys)

# sys.setdefaultencoding('utf8')
now = d.datetime.now()
print(f'Rapor Alınmaya Başladı. . .({now})')
#Turkish Months
months = ['', u'Ocak', u'Şubat', u'Mart', u'Nisan', u'Mayıs', u'Haziran',
          u'Temmuz', u'Ağustos', u'Eylül', u'Ekim', u'Kasım', u'Aralık']

yy_ank_project_list = []
yy_ank_assg_list = []
yy_ank_priority_list = []
yy_ank_state_list = []
ig_ank_project_list = []
Ejemplo n.º 14
0
    def calculate():
        def dialog_box_close():
            dialog_box.destroy()

        def result_frame_close():
            result_frame.destroy()

        print(cal.get_date())
        if home_team_dropdown_var.get() == away_team_dropdown_var.get():
            #when the team is same
            dialog_box = tk.Toplevel()
            dialog_box.geometry("350x115")

            ok_button = tk.Button(dialog_box,
                                  text="OK",
                                  command=dialog_box_close,
                                  height=2,
                                  width=7)

            message = tk.Label(dialog_box,
                               text="Please choose a different team",
                               font=("Helvetica", 14))

            print(utils.get_image_path("error"))
            loader = Image.open(utils.get_image_path("error"))
            loader = loader.resize((60, 50))
            err_img = ImageTk.PhotoImage(loader)
            err_label = tk.Label(dialog_box, image=err_img)
            err_label.image = err_img

            err_label.place(x=10, y=10)
            message.place(x=70, y=20)
            ok_button.place(x=155, y=55)

            dialog_box.mainloop()
        elif home_team_dropdown_var.get(
        ) == "Home Team" or away_team_dropdown_var.get() == "Away Team":
            #when home and away is empty
            dialog_box = tk.Toplevel()
            dialog_box.geometry("350x115")

            message = tk.Label(dialog_box,
                               text="Team field cannot be empty",
                               font=("Helvetica", 14))

            ok_button = tk.Button(dialog_box,
                                  text="OK",
                                  command=dialog_box_close,
                                  height=2,
                                  width=7)

            loader = Image.open(utils.get_image_path("error"))
            loader = loader.resize((60, 50))
            err_img = ImageTk.PhotoImage(loader)
            err_label = tk.Label(dialog_box, image=err_img)
            err_label.image = err_img

            err_label.place(x=10, y=10)
            message.place(x=85, y=20)
            ok_button.place(x=155, y=55)

            dialog_box.mainloop()
        elif cal.get_date() == "":
            #when date is not picked
            dialog_box = tk.Toplevel()
            dialog_box.geometry("350x115")

            message = tk.Label(dialog_box,
                               text="Date field cannot be empty",
                               font=("Helvetica", 14))

            ok_button = tk.Button(dialog_box,
                                  text="OK",
                                  command=dialog_box_close,
                                  height=2,
                                  width=7)

            loader = Image.open(utils.get_image_path("error"))
            loader = loader.resize((60, 50))
            err_img = ImageTk.PhotoImage(loader)
            err_label = tk.Label(dialog_box, image=err_img)
            err_label.image = err_img

            err_label.place(x=10, y=10)
            message.place(x=85, y=20)
            ok_button.place(x=155, y=55)

            dialog_box.mainloop()
        else:
            #do the calculation
            result_frame = tk.Toplevel()
            result_frame.geometry("350x330")

            home_team = home_team_dropdown_var.get()
            away_team = away_team_dropdown_var.get()
            date = cal.get_date()
            season = utils.get_season(date)

            utils.generate_data_for_calculation(home_team, away_team,
                                                utils.get_year(date))

            result = calculation.calculate(home_team, away_team, season)

            home_info = tk.Label(result_frame,
                                 text="Home Team : " + home_team,
                                 font=("Helvetica", 13))

            away_info = tk.Label(result_frame,
                                 text="Away Team : " + away_team,
                                 font=("Helvetica", 13))

            date_info = tk.Label(result_frame,
                                 text="Date           : " + date,
                                 font=("Helvetica", 13))

            season_info = tk.Label(result_frame,
                                   text="Season       : " + season,
                                   font=("Helvetica", 13))

            result_info = tk.Label(result_frame,
                                   text="Result : ",
                                   font=("Helvetica", 15))

            home_win = tk.Label(result_frame,
                                text="Home Win   : " + str(result[0]) + "%",
                                font=("Helvetica", 13))

            home_draw = tk.Label(result_frame,
                                 text="Draw           : " + str(result[1]) +
                                 "%",
                                 font=("Helvetica", 13))

            home_lose = tk.Label(result_frame,
                                 text="Home Lose  : " + str(result[2]) + "%",
                                 font=("Helvetica", 13))

            the_button = tk.Button(result_frame,
                                   text="OK",
                                   command=result_frame_close,
                                   height=2,
                                   width=7)

            #deployment
            home_info.place(x=20, y=20)
            away_info.place(x=20, y=50)
            date_info.place(x=20, y=80)
            season_info.place(x=20, y=110)
            result_info.place(x=20, y=150)
            home_win.place(x=20, y=180)
            home_draw.place(x=20, y=210)
            home_lose.place(x=20, y=240)
            the_button.place(x=140, y=280)
            result_frame.mainloop()
Ejemplo n.º 15
0
import calculation

def repeat(func, message):
    answer = ''
    while answer.upper() != 'N':
        answer = input('Do you want to repeat? Enter Y/N:')
        if answer.upper() == 'Y':
            user_input = input(message)
            func(user_input)
        elif answer.upper() != 'N':
            print('Wrong answer! You should enter Y or N')
            continue

message = 'Enter a statement to calculate (for dates - dd.mm.yyyy):'
user_input = input(message)
calculation.calculate(user_input)
repeat(calculation.calculate, message)

# 2.2 var
# from math import *
#
# def repeat(func, message):
#     answer = ''
#     while answer.upper() != 'N':
#         answer = input('Do you want to repeat? Enter Y/N:')
#         if answer.upper() == 'Y':
#             user_input = input(message)
#             func(user_input)
#         elif answer.upper() != 'N':
#             print('Wrong answer! You should enter Y or N')
#             continue