Beispiel #1
0
def testIsInt(x):
    sys.path.append('../project/sugarlabs-calculate-sugar-0.94')
    from functions import is_int

    try:
        output = is_int(x)
    except:
        output = "Fail"
    return output
Beispiel #2
0
def get_commits_sizes(user: str, repo: str, shas: list) -> list:
    commits_sizes = []
    for sha in shas:
        url = '/'.join([git_api_base, user, repo, "git/trees", str(sha)])
        try:
            result = requests.get(url)
            data = json.loads(result.text)
            tree = str(data).split("'tree':")[1]
            sizes_in_tree = tree.split("'size':")
            tree_sizes = []
            for size in sizes_in_tree:
                value = size.split(',')[0]
                if is_int(value):
                    tree_sizes.append(int(value))
            commits_sizes.append(sum(tree_sizes))
        except Exception as e:
            print(str(e))
    return commits_sizes
Beispiel #3
0
    def Check_Options(self):

        functions.globstring = "./GenCoF-master/Sickle/sickle-master/sickle"
        errors = ''

        if (self.var_se_pe.get() == "Paired-end"):
            functions.args_se_pe(self.var_se_pe.get())
            if (self.var_g.get()):
                functions.args_se_and_pe_non_man("-g", "")

            if (self.var_reverse_file == ''):

                if ((".fastq" not in self.var_filename
                     and ".fq" not in self.var_filename)
                        or self.var_filename == ''):
                    errors += "Enter file with .fastq or .fq appended to the end\n"
                else:
                    functions.file_input_inter(self.var_filename)

                if (self.var_qual.get() != "Pick Quality Type"):
                    functions.quality_vals(self.var_qual.get())
                else:
                    errors += "Enter quality type\n"

                if (self.var_m.get()):
                    if (self.var_g.get()):
                        if (self.var_out_file.get() == '' or
                                self.var_out_file.get() == 'Output Filename'):
                            functions.inter_big_m('TRIMMED_OUTPUT.fastq.gz')
                        elif (".fastq" not in self.var_out_file.get()
                              and ".fq" not in self.var_out_file.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.inter_big_m(self.var_out_file.get() +
                                                  '.gz')
                    else:
                        if (self.var_out_file.get() == '' or
                                self.var_out_file.get() == 'Output Filename'):
                            functions.inter_big_m('TRIMMED_OUTPUT.fastq')
                        elif (".fastq" not in self.var_out_file.get()
                              and ".fq" not in self.var_out_file.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.inter_big_m(self.var_out_file.get())

                else:
                    if (self.var_g.get()):
                        if (self.var_out_file.get() == '' or
                                self.var_out_file.get() == 'Output Filename'):
                            functions.inter_m('TRIMMED_OUTPUT.fastq.gz')
                        elif (".fastq" not in self.var_out_file.get()
                              and ".fq" not in self.var_out_file.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.inter_m(self.var_out_file.get() + '.gz')

                        if (self.var_singles.get() == ''
                                or self.var_singles.get()
                                == 'Trimmed Singles Filename'):
                            functions.trimmed('TRIMMED_SINGLES.fastq.gz')
                        elif (".fastq" not in self.var_singles.get()
                              and ".fq" not in self.var_singles.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.trimmed(self.var_singles.get() + '.gz')
                    else:
                        if (self.var_out_file.get() == '' or
                                self.var_out_file.get() == 'Output Filename'):
                            functions.inter_m('TRIMMED_OUTPUT.fastq')
                        elif (".fastq" not in self.var_out_file.get()
                              and ".fq" not in self.var_out_file.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.inter_m(self.var_out_file.get())

                        if (self.var_singles.get() == ''
                                or self.var_singles.get()
                                == 'Trimmed Singles Filename'):
                            functions.trimmed('TRIMMED_SINGLES.fastq')
                        elif (".fastq" not in self.var_singles.get()
                              and ".fq" not in self.var_singles.get()):
                            errors += "Enter file with .fastq or .fq appended to the end\n"
                        else:
                            functions.trimmed(self.var_singles.get())

            else:
                if ((".fastq" not in self.var_filename
                     and ".fq" not in self.var_filename)
                        or (self.var_filename == '')):
                    errors += "Enter file with .fastq or .fq appended to the end\n"
                else:
                    functions.file_input(self.var_filename)

                if (".fastq" not in self.var_reverse_file
                        and ".fq" not in self.var_reverse_file):
                    errors += "Enter file with .fastq or .fq appended to the end or clear contents of reverse entry\n"
                else:
                    functions.file_rev_input(self.var_reverse_file)

                if (self.var_qual.get() != "Pick Quality Type"):
                    functions.quality_vals(self.var_qual.get())
                else:
                    errors += "Enter quality value\n"

                if (self.var_g.get()):
                    if (self.var_out_file.get() == ''
                            or self.var_out_file.get() == 'Output Filename'):
                        functions.output('TRIMMED_OUTPUT.fastq.gz')
                    elif ('.fastq' not in self.var_out_file.get()
                          and ".fq" not in self.var_out_file.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.output(self.var_out_file.get() + '.gz')
                else:
                    if (self.var_out_file.get() == ''
                            or self.var_out_file.get() == 'Output Filename'):
                        functions.output('TRIMMED_OUTPUT.fastq')
                    elif ('.fastq' not in self.var_out_file.get()
                          and ".fq" not in self.var_out_file.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.output(self.var_out_file.get())

                if (self.var_g.get()):
                    if (self.var_reverse_output.get() == ''
                            or self.var_reverse_output.get()
                            == 'Trimmed PE Reverse Output Filename'):
                        functions.output_rev('TRIMMED_OUTPUT_REV.fastq.gz')
                    elif (".fastq" not in self.var_reverse_output.get()
                          and ".fq" not in self.var_reverse_output.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.output_rev(self.var_reverse_output.get() +
                                             '.gz')
                else:
                    if (self.var_reverse_output.get() == ''
                            or self.var_reverse_output.get()
                            == 'Trimmed PE Reverse Output Filename'):
                        functions.output_rev('TRIMMED_OUTPUT_REV.fastq')
                    elif (".fastq" not in self.var_reverse_output.get()
                          and ".fq" not in self.var_reverse_output.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.output_rev(self.var_reverse_output.get())

                if (self.var_g.get()):
                    if (self.var_singles.get() == '' or self.var_singles.get()
                            == 'Trimmed Singles Filename'):
                        functions.trimmed('TRIMMED_SINGLES.fastq.gz')
                    elif (".fastq" not in self.var_singles.get()
                          and ".fq" not in self.var_singles.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.trimmed(self.var_singles.get() + '.gz')
                else:
                    if (self.var_singles.get() == '' or self.var_singles.get()
                            == 'Trimmed Singles Filename'):
                        functions.trimmed('TRIMMED_SINGLES.fastq')
                    elif (".fastq" not in self.var_singles.get()
                          and ".fq" not in self.var_singles.get()):
                        errors += "Enter file with .fastq or .fq appended to the end\n"
                    else:
                        functions.trimmed(self.var_singles.get())

        elif (self.var_se_pe.get() == "Single-end            "):
            functions.args_se_pe(self.var_se_pe.get())

            if ((".fastq" not in self.var_filename
                 and ".fq" not in self.var_filename)
                    or (self.var_filename == '')):
                errors += "Pick file with .fastq or .fq appended to the end\n"
            else:
                functions.file_input(self.var_filename)

            if (self.var_qual.get() != "Pick Quality Type"):
                functions.quality_vals(self.var_qual.get())
            else:
                errors += "Enter quality value\n"

            if (self.var_g.get()):
                if (self.var_out_file.get() == ''
                        or self.var_out_file.get() == 'Output Filename'):
                    functions.output('TRIMMED_OUTPUT.fastq.gz')
                elif (".fastq" not in self.var_out_file.get()
                      or ".fq" not in self.var_out_file.get()):
                    errors += "Enter file with .fastq or .fq appended to the end\n"
                else:
                    functions.output(self.var_out_file.get() + '.gz')

            else:
                if (self.var_out_file.get() == ''
                        or self.var_out_file.get() == 'Output Filename'):
                    functions.output('TRIMMED_OUTPUT.fastq')
                elif (".fastq" not in self.var_out_file.get()
                      or ".fq" not in self.var_out_file.get()):
                    errors += "Enter file with .fastq or .fq appended to the end\n"
                else:
                    functions.output(self.var_out_file.get())

        else:
            errors += "Enter SE or PE\n"

        if (functions.is_int(self.var_q_num.get())):
            functions.args_se_and_pe_non_man("-q", int(self.var_q_num.get()))

        if (functions.is_int(self.var_L_num.get())):
            functions.args_se_and_pe_non_man("-l", int(self.var_L_num.get()))

        if (self.var_x.get()):
            functions.args_se_and_pe_non_man("-x", "")

        if (self.var_n.get()):
            functions.args_se_and_pe_non_man("-n", "")

        self.err_message.config(text="Running....", font="Times 18")
        self.update()
        if (errors == ''):
            cmd_line = shlex.split(functions.globstring)
            if ('sickle'
                    in os.listdir('./GenCoF-master/Sickle/sickle-master/')):
                subprocess.call([
                    'chmod', '+x',
                    './GenCoF-master/Sickle/sickle-master/sickle'
                ])
                p = subprocess.Popen(cmd_line,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
                result, error = p.communicate()
                if (error.decode('utf-8') == ''):
                    self.err_message.config(text="OUTPUT: \n" +
                                            result.decode('utf-8'),
                                            font="Times 18")
                else:
                    self.err_message.config(text='\nERRORS: \n' +
                                            error.decode('utf-8'),
                                            font="Times 18")
            elif ('sickle'
                  not in os.listdir('./GenCoF-master/Sickle/sickle-master/')
                  and 'Makefile'
                  in os.listdir('./GenCoF-master/Sickle/sickle-master/')):
                subprocess.call(
                    ["make", "-C", "./GenCoF-master/Sickle/sickle-master/"])
                p = subprocess.Popen(cmd_line,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
                result, error = p.communicate()
                if (error.decode('utf-8') == ''):
                    self.err_message.config(text="\n" + result.decode('utf-8'),
                                            font="Times 18")
                else:
                    self.err_message.config(text='\n' + error.decode('utf-8'),
                                            font="Times 18")
            else:
                self.err_message.config(
                    text="ERRORS: \n makefile not in correct directory",
                    fg='dark red',
                    font="Times 18")
        else:
            self.err_message.config(text=('ERRORS: \n' + errors),
                                    fg='dark red',
                                    font="Times 18")

        return
Beispiel #4
0
def on_chat_message(msg):

    global model_choice_store
    content_type, chat_type, chat_id = telepot.glance(msg)

    input_data = msg['text']
    if chat_id in model_choice_store:
        model_choice = model_choice_store[chat_id]
    else:
        model_choice = None

    if input_data == '/start':
        keyboard = InlineKeyboardMarkup(
            inline_keyboard=[[
                InlineKeyboardButton(text=u'Прогноз добычи "сланцевой" нефти',
                                     callback_data='shale')
            ],
                             [
                                 InlineKeyboardButton(
                                     text=u'ВИЭ Европы',
                                     callback_data='renewables')
                             ]])
        TelegramBot.sendMessage(
            chat_id,
            u'Выберите модель. Для изменения выбора нажмите /start или другую кнопку',
            reply_markup=keyboard)

    elif model_choice == 'shale':
        input_data = input_data.split(
        )  # введённый текст переделываем в массив

        if input_data[0][:1] == '/':
            input_data[0] = input_data[0][1:]  # обрезаем слеш

        if is_int(input_data[0]) is True and is_float(input_data[1]) is True:
            input_data = list(map(float,
                                  input_data))  # сценарии буровых в float
            input_data[0] = int(input_data[0])  # месяцы в int
            draw_shale(input_data)  # запуск модели с входными параметрами
            time.sleep(1)
            TelegramBot.sendPhoto(chat_id,
                                  open('chart_shale.png',
                                       'rb'))  # отправка графика в чат
        else:
            TelegramBot.sendMessage(chat_id,
                                    'Shale oil forecast: Wrong arguments')

    elif model_choice == 'renewables':
        input_data = input_data.split(
        )  # введённый текст переделываем в массив

        if input_data[0][:1] == '/':
            input_data[0] = input_data[0][1:]  # обрезаем слеш

        if is_int(input_data[0]) is True and is_float(input_data[1]) is True and is_float(input_data[2]) is True and is_float(input_data[2]) is True \
           and len(input_data) == 4:
            print 'renew entered'
            input_data = list(map(float,
                                  input_data))  # сценарии буровых в float
            month = int(input_data[0] - 1)
            start_date = month * 30.4
            end_date = start_date + 30.4
            wind_multiplier = [input_data[1]]
            solar_multiplier = [input_data[2]]
            capacity_storage = [input_data[3]]
            input_data[0] = int(input_data[0])  # месяцы в int
            draw_renew(1, wind_multiplier, solar_multiplier, capacity_storage,
                       wind_price, solar_price, gas_price, price_kwh_storage,
                       discount_rate_storage, years_storage, start_date,
                       end_date)  # запуск модели с входными параметрами
            time.sleep(1)
            TelegramBot.sendPhoto(chat_id,
                                  open('chart_renew.png',
                                       'rb'))  # отправка графика в чат
        else:
            TelegramBot.sendMessage(chat_id,
                                    'Europe renewables: Wrong arguments')
# Will print a message in preparation for testing of the function
def prep_msg(func):
    print("Beginning testing of the " + func + " function...")


# Total number of test cases per function: 4
# Total number of functions: 8
# Total number of test cases: 32 test cases
total_test = 32
total_passed = 0

# Testing is_int() function
prep_msg("is_int()")

if functions.is_int(1):
    pass_msg(test_Case_msg("1", "is_int()"))
    total_passed += 1
else:
    err_msg(test_Case_msg("1", "is_int()"))

if not functions.is_int(3.14):
    pass_msg(test_Case_msg("2", "is_int()"))
    total_passed += 1
else:
    err_msg(test_Case_msg("2", "is_int()"))

if not functions.is_int("Hello!"):
    pass_msg(test_Case_msg("3", "is_int()"))
    total_passed += 1
else: