import os
from os.path import join

import argparse

from calibrator.tools.train_task_net import train as train_source
from calibrator.tools.test_task_net import load_and_test_net
from calibrator.tools.train_calibrator_net import train_calibrator
import torch
import numpy as np
from torch.utils.data import DataLoader
import yaml
import ast

parser = argparse.ArgumentParser(description='')

parser.add_argument('--yaml_path', type = str, default = '')

args = parser.parse_args()
gpu_num = torch.cuda.device_count()
#np.random.seed(4325)

###################################
# Set to your preferred data path #
###################################

###################################

# Choose GPU ID

try:
    with open (args.yaml_path,'r') as file:
        cfg = yaml.safe_load(file)
except Exception as e:
    print ('Error reading the config file')

adatadir = cfg['TRAIN']['DATA_DIR']

# Problem Params

src = cfg['DATASET']['SRC']
tgt = cfg['DATASET']['TGT']

base_src = src.split('2')[0]

src_net_arch = cfg['SRC_NET']['ARCH']
num_cls = cfg['SRC_NET']['NUM_CLS']

# Output directory

outdir = '{}/{}_to_{}'.format(cfg['TRAIN']['RESULT_DIR'],
                                           src,tgt)

datadir = cfg['TRAIN']['DATA_DIR']

src_net_file = join(outdir, '{}_net_{}.pth'.format(src_net_arch, src))

calibrator_net_file = join(outdir, 'calibrator_{:s}_net_{:s}_{:s}.pth'
                           .format(src_net_arch, src, tgt))

cfg['PATH'] = {}

cfg['PATH']['OUTDIR'] = outdir

cfg['PATH']['SRC_NET_PATH'] = src_net_file

cfg['PATH']['CALIBRATOR_NET_PATH'] = calibrator_net_file

src_datadir = join(datadir, src)
tgt_datadir = join(datadir, tgt)

# Optimization Params

betas = cfg['OPTIMIZER']['ADAM']['BETAS']#(0.9, 0.999)  # Adam default

betas = ast.literal_eval(betas)

cfg['OPTIMIZER']['ADAM']['BETAS'] = betas

#######################
# 1. Train Source Net #
#######################

if os.path.exists(src_net_file):
    print('Skipping source net training, exists:', src_net_file)
else:
    train_source(src, src_datadir, cfg)

#####################
# 2. Train Calibrator Net #
#####################

if os.path.exists(calibrator_net_file):
    print('Skipping calibrator training, exists:', calibrator_net_file)
else:
    train_calibrator(cfg,src_net_file)

##############################
# 3. Evaluate source and calibrator #
##############################

if src == base_src:
    print('----------------')
    print('Test set:', src)
    print('----------------')
    print('Evaluating {} source model: {}'.format(src, src_net_file))
    load_and_test_net(src, src_datadir, src_net_file, src_net_arch,cfg,
                      dset='test')

print('----------------')
print('Test set:', tgt)
print('----------------')
print('Evaluating {} source model: {}'.format(src, src_net_file))
cm = load_and_test_net(tgt, tgt_datadir, src_net_file, src_net_arch,cfg,
                       dset='test')

print('Evaluating {}->{} calibrator model: {}'.format(src, tgt, calibrator_net_file))
cm = load_and_test_net(tgt, tgt_datadir, calibrator_net_file, 'CalibratorNet', cfg,
                       dset='test')

print('Evaluating {}->{} calibrator model: {}'.format(src, src, calibrator_net_file))
cm = load_and_test_net(src, src_datadir, calibrator_net_file, 'CalibratorNet', cfg,
                       dset='test')
print(cm)


import csv
import io
from dwd_utils import mosmix
from dwd_utils.poi2MosmixMap import poi2MosmixMap
from datetime import datetime

def mosmixDataTimeStamp():
    return datetime.strptime(mosmix.MosmixData().getMosmixDataTimestamp(),
        #Fri, 27 Mar 2015 08:05:42 GMT
        '%a, %d %b %Y %X %Z')

def mosmixDataStream():
    mosmixData = mosmix.MosmixData().getStationsDataByIds(set(poi2MosmixMap.values()), {'ww'}, range(3,9))
    f = io.StringIO()
    csv_writer = csv.writer(f)
    for k in poi2MosmixMap:
        a = []
        a.append(k)
        a.extend(extractForecastsForCoord(poi2MosmixMap[k], mosmixData))
        csv_writer.writerow(a)
    f.seek(0)
    return f

def extractForecastsForCoord(latLon, mosmixData):
    return list(map(lambda lev: levelToMatrix(lev),
                    map(lambda ww: wwToLevel(int(float(ww))) + 1,
                        map(lambda forecast: forecast['values']['ww'],
                            mosmixData[latLon]['forecasts'],
                            ))))

# see https://www.dwd.de/DE/leistungen/opendata/help/schluessel_datenformate/kml/mosmix_element_weather_xls.xlsx
wwToLevelMap = {
    95:3,
    57:5,
    56:2,
    67:5,
    66:2,
    86:5,
    85:2,
    84:5,
    83:2,
    82:6,
    81:5,
    80:2,
    75:6,
    73:4,
    71:2,
    69:5,
    68:2,
    55:6,
    53:4,
    51:2,
    65:6,
    63:4,
    61:2,
    49:0,
    45:0,
    3:0,
    2:0,
    1:0,
    0:0
}

def wwToLevel(ww):
    if ww in wwToLevelMap:
        return wwToLevelMap[ww]
    else:
        return 0

def levelToMatrix(level):
    if level > 8:
        level = 8
    matrix = ['1' for i in range(level)]
    matrix.extend(['0' for i in range(8 - level)])
    return ''.join(matrix)

if __name__ == "__main__":
    print(mosmixDataTimeStamp())
    with mosmixDataStream() as file:
       for row in csv.reader(file):
           if row[0] == '70599':
               print(row)


import time

from Functions.data_preparation import write_state
from Functions.logger import create_logger
from datetime import datetime
import pytz

from influxdb import InfluxDBClient
from Functions.consts import influxdb_conndata

from Functions.data_preparation import get_last_candles

class BotManager():

    bots = {}
    influx = None

    def __init__(self, account_name, strategy, trader, bitmex_params, trader_params, strategy_params, restore_state=True):
        self.name = account_name + '_' + strategy.__name__ + '_' +  trader.__name__
        self.account_name = account_name
        self.strategy_name = strategy.__name__
        self.trader_name = trader.__name__
        self.logger = create_logger(self.name)
        self.strategy = strategy(self.logger, **strategy_params)
        self.trader = trader(self.logger, self.strategy, bitmex_params, **trader_params)
        if restore_state:
            self.trader.load_state(self.account_name)
        self.initial_balance, _ = self.trader.balances_status()

    def log_balance(self):
        total, realised_pnl = self.trader.balances_status()

        # for plots
        write_state('../logs/{}/balances.csv'.format(self.name), total)
        write_state('../logs/{}/realised_pnls.csv'.format(self.name), realised_pnl)

        status = [
            {
                "measurement": "balance",
                "tags": {
                    "account": self.account_name,
                    "strategy": self.strategy_name,
                    "trader": self.trader_name,
                },
                "time": datetime.now(pytz.utc),
                "fields": {
                    'Total balance': total,
                    'Balance change since start': ((total + realised_pnl) / self.initial_balance - 1.) * 100,
                    'Realised PnL': realised_pnl
                }
            }
        ]
        BotManager.influx.write_points(status)

        self.logger.info(
            f"Total balance: {total}, "
            f"Balance change since start: {((total+realised_pnl)/self.initial_balance - 1.)*100}%, "
            f"Realised PnL: {realised_pnl}")

        time_last_check = time.time()

    @staticmethod
    def addBot(account_name, strategy, trader, bitmex_params, trader_params, strategy_params, restore_state=True):
        bot = BotManager(account_name, strategy, trader, bitmex_params, trader_params, strategy_params, restore_state)
        BotManager.bots[bot.name] = bot

    @staticmethod
    def run():

        BotManager.influx = InfluxDBClient(**influxdb_conndata)

        logger = create_logger('bot_manager')
        logger.info("Start of work")

        start_time_offset = 0.5
        time_to_wait_new_trade = 60# * 60
        time_to_wait_new_balance_check = 61# * 10

        safe_stop = False

        while not safe_stop:
            try:
                now = round(time.time())

                if now % time_to_wait_new_trade == 0:
                    logger.info("Start make prediction")
                    time.sleep(start_time_offset)
                    dt_trade = time.time()
                    candles = get_last_candles(timeframe='1m')

                    for bot in BotManager.bots:
                        BotManager.bots[bot].trader.exec_trade(candles)
                        BotManager.bots[bot].trader.save_state(BotManager.bots[bot].account_name)
#                        time.sleep(0.5)

                    dt_trade = time.time() - dt_trade
                    time_last_trade = time.time() - dt_trade

                if now % time_to_wait_new_balance_check == 0:

                    for bot in BotManager.bots:
                        BotManager.bots[bot].log_balance()

            except Exception as e:
                logger.info("EXCEPTION: " + str(e))
            except KeyboardInterrupt:
                safe_stop = True
                logger.info('Stopping gracefully')
            finally:
                time.sleep(1)


# Given an article find the genuity of it.
from bs4 import BeautifulSoup
import requests, urllib2
from lxml.html import fromstring

import jellyfish
import re, math
from collections import Counter
from nltk.corpus import stopwords
from nltk.stem import SnowballStemmer
import glob
import os
import random
import pandas as pd
import itertools
LANG='english'
# source = "http://abc7news.com/politics/former-pres-obama-spotted-in-san-francisco/3521667/"
WORD = re.compile(r'\w+')

def get_cosine(vec1, vec2):
     intersection = set(vec1.keys()) & set(vec2.keys())
     numerator = sum([vec1[x] * vec2[x] for x in intersection])

     sum1 = sum([vec1[x]**2 for x in vec1.keys()])
     sum2 = sum([vec2[x]**2 for x in vec2.keys()])
     denominator = math.sqrt(sum1) * math.sqrt(sum2)

     if not denominator:
        return 0.0
     else:
        return float(numerator) / denominator

def text_to_vector(text):
     words = WORD.findall(text.lower())

     #remove stop words
     stop = set(stopwords.words(LANG))
     stopwordsRemoved=[i for i in words if i not in stop]

     #stemming
     stemmer = SnowballStemmer(LANG)
     stemWords=[stemmer.stem(i) for i in stopwordsRemoved ]

     #print stemWords
     #print Counter(stemWords)
     return Counter(stemWords)

def processText(webpage):
    proc_text = []

    try:
        news_open = urllib2.urlopen(webpage)
        news_soup = BeautifulSoup(news_open, "lxml")
        news_para = news_soup.find_all("p", text = True)
        for item in news_para:
            para_text = (' ').join((item.text).split())
            proc_text.append(para_text)

    except urllib2.HTTPError:
        pass
    return proc_text

def get_closest_match(x,list_strings):
    best_match=None
    highest_jw=0

    for current_string in list_strings:
        current_score=jellyfish.jaro_winkler(unicode(x),unicode(current_string))

        if current_score >highest_jw :
            highest_jw =current_score
            best_match=current_string

    return best_match

def get_reputation_score(url):
    Reputations=pd.read_csv("reputations.csv")
    matching=get_closest_match(url,list(Reputations['source']))
    #print (float(Reputations[Reputations['source']==matching]['ScaledRepo'].iloc[0]))
    return float(Reputations[Reputations['source']==matching]['ScaledRepo'].iloc[0])

def set_reputation_score(url,score):
     Reputations=pd.read_csv("reputations.csv")
     matching=get_closest_match(url,list(Reputations['source']))
     newScore=0.9*Reputations[Reputations['source']==matching]['ScaledRepo'].iloc[0]+0.1*score
     loci=Reputations.index[Reputations['source'] == matching].tolist()[0]
     Reputations.loc[loci,'ScaledRepo']=newScore
     Reputations.to_csv("reputations.csv",index=False)

TweetLink=pd.read_csv("../geotweets.csv")
linkArray=list(set(TweetLink.dropna()['longitude'].values))
#print linkArray
df_ = pd.DataFrame(columns=['source','Headline','Body','Relevancy'])
for source in linkArray:
    url = requests.get(source)
    #print source
    tree = fromstring(url.content)
    if tree is not None:
        title = tree.findtext('.//title')

        body = ''.join(BeautifulSoup(url.text, "html.parser").stripped_strings)
        processed_text = processText(source)

        cosine_scores=[]
        irrelavecy_index = 0
        score=0

        #print processed_text
        for text in processed_text:
            vector1 = text_to_vector(title)
            vector2 = text_to_vector(text)
            cosine = get_cosine(vector1, vector2)
            if cosine != 0.0:
                irrelavecy_index = (irrelavecy_index + 1)
                cosine_scores.append(cosine)
                if len(processed_text) != 0:
                    irrelavecy_index = irrelavecy_index / float(len(processed_text))
                    relavency_score =irrelavecy_index

                    rep_score = get_reputation_score(source)
                    #print(relavency_score)
                    relavency_score = (rep_score + relavency_score) / 2
                    score= relavency_score
                    set_reputation_score(source, relavency_score)

                    #print(rep_score)
                    #print "Relavancy(%)=",100-100*relavency_score

        if len(processed_text)>1:
            data = {'source': source, 'Headline': title,'Body':' '.join(processed_text) ,'Relevancy':100-100*score}
            dataframeing=pd.DataFrame(data=data, index=[0])
            listdf=[df_,dataframeing]
            df_ = pd.concat(listdf,sort=False,ignore_index=True)

df_.to_csv('truaidnas.csv',index=False,encoding='utf-8')


import pandas as pd
import datetime
import time
import tushare as ts
import warnings
warnings.filterwarnings("ignore")  # 忽略警告信息，警告不是报错，不会影响程序执行

# 1. 数据预处理
# 读取数据、删除重复及空值行
df = pd.read_excel('/Users/macbookair/Desktop/数据分析/书本配套资料及电子书/python/Python金融/0.《Python金融》最新配套源代码文件（2020-12-07完善）/第12章源代码汇总/分析师评级报告.xlsx',
                   dtype={'股票代码': str}) # 注意设置dtype参数，让股票代码以字符串格式读进来
df = df.drop_duplicates()  # 删除重复行
df = df.dropna(thresh=5)  # 删除空值行，thresh=5表示非空值少于5个则删除，本案例因为没有空值行，其实可以不写

#修改日期格式
# t_list = []  #for循环选出需要数据，存为列表
# for i in df['报告日期']:
# 	i = str(i)
# 	t1 = time.strptime(i, "%Y-%m-%d")   #转换成datetime.datetime格式的日期
# 	t2 = time.strftime("%Y%m%d", t1)  #转换成字符串格式
# 	t_list.append(t2)
#
# df['报告日期'] = t_list  #将列表添加进原本的表格数据中

# 2.通过Tushare库计算股票收益率
df_use = df.iloc[0:100]  # 为了演示选取了前100行，想运行全部可写df_use = df
rate = []  # 创建一个空列表，用来存储每支股票的收益率

for i, row in df_use.iterrows():
    code = row['股票代码']
    analysist_date = row['报告日期']

    # 1.获取开始日期，也即第二天
    begin_date = datetime.datetime.strptime(analysist_date, '%Y-%m-%d')
    begin_date = begin_date + datetime.timedelta(days=1)
    begin_date = begin_date.strftime('%Y-%m-%d')

    # 2.获取结束日期，也即第三十天
    end_date = datetime.datetime.strptime(analysist_date, '%Y-%m-%d')
    end_date = end_date + datetime.timedelta(days=30)
    end_date = end_date.strftime('%Y-%m-%d')

    # 3.通过Tushare库计算股票收益率 #老接口取数失效，采用新接口注意格式：直接用股票序号去匹配无效，格式为：00002.sz
    ts_result = ts.get_hist_data(code, begin_date, end_date)
    if ts_result is None or len(ts_result) < 5:  # 防止股票没有数据
        return_rate = 0
    else:
        start_price = ts_result.iloc[-1]['open']
        end_price = ts_result.iloc[0]['close']
        return_rate = (end_price / start_price) - 1.0
    rate.append(return_rate)

df_use['30天收益率'] = rate  # 该添加列的方式参考6.2.1小节

# 导出为Excel
df_use.to_excel('30天收益率.xlsx')

print(df_use)
print('30天收益率计算完毕！')
# 如果让你使用Tushare pro，可以查看www.huaxiaozhi.com上的教程，如果Tushare普通还能获取结果，不用pro也无所谓

基于评级报告的投资决策分析/计算平均收益率进行分析师傅预测准确度排名.py

计算平均收益率进行分析师傅预测准确度排名.py


from lib.book import Book
class BookRepository:

    def __init__(self, connection):
        self._connection = connection
    #select all records
    #No arguments
    def all(self):
        rows = self._connection.execute('SELECT * from books')
        books = []
        for row in rows:
            item = Book(row["title"], row["author_name"],)
            books.append(item)
        return books

        # Executes the SQL query:
        # SELECT title, author_name, FROM books;

        # Returns an array of Student objects.


import os
from os import listdir
import numpy as np
from numpy import asarray
import cv2
from openvino.inference_engine import IECore
from numpy import savez_compressed

model_xml=r"C:\Users\LENOVO\Desktop\Detect&Recognize\intel\face-detection-0202\FP16\face-detection-0202.xml"
model_bin=os.path.splitext(model_xml)[0] +'.bin'

def output_handler(frame,result,height,width):
	faces=list()
	for box in result[0][0]:
		if box[2] >=0.5:
			xmin=int(box[3] * width)
			ymin=int(box[4] *height)
			xmax=int(box[5] * width)
			ymax=int(box[6] *height)

			face=frame[ymin:ymax,xmin:xmax]
			face=cv2.resize(face,(112,112))

			faces.append(face)

	return faces

def extract_face(filename):
	plugin=IECore()
	net=plugin.read_network(model=model_xml,weights=model_bin)
	exec_net=plugin.load_network(network=net,device_name="CPU")
	input_blob=list(net.input_info.keys())[0]
	output_blob=next(iter(net.outputs))
	b,c,h,w=net.input_info[input_blob].input_data.shape

	image=cv2.imread(filename)
	height=image.shape[0]
	width=image.shape[1]

	p_image=cv2.resize(image,(w,h))
	p_image=p_image.transpose((2,0,1))
	p_image=p_image.reshape(1,3,h,w)

	infer_request=exec_net.start_async(request_id=0,inputs={input_blob:p_image})
	status=exec_net.requests[0].wait(-1)

	if status==0:
		result=exec_net.requests[0].outputs[output_blob]

		return output_handler(image,result,height,width)[0]

def load_faces(directory):
	faces=list()

	#enumerate files
	for filename in listdir(directory):
		#path
		path=directory+filename
		#get face
		face=extract_face(path)
		#store
		faces.append(face)
	return faces

def load_dataset(directory):
	X,y=list(),list()

	#enumerate folders on per class
	for subdir in listdir(directory):
		#path
		path=directory + subdir + '/'

		#load all faces in the subdirectory
		faces=load_faces(path)

		#create labels
		labels=[subdir for _ in range(len(faces))]

		#Summarize progress
		print('> loaded %d examples for class: %s' %(len(faces),subdir))

		#store
		X.extend(faces)
		y.extend(labels)

	return asarray(X),asarray(y)

trainX,trainy=load_dataset("C:/Users/LENOVO/Desktop/Detect&Recognize/images/train/")
print(trainX.shape, trainy.shape)

testX,testy=load_dataset("C:/Users/LENOVO/Desktop/Detect&Recognize/images/val/")
savez_compressed('blaise-unknown-dataset.npz', trainX, trainy, testX, testy)


import tensorflow as tf
import numpy as np
from tensorflow import keras
from tensorboard.plugins.hparams import api as hp

#for tensorboard
import os

# network and training
EPOCHS = 20
BATCH_SIZE = 128
VERBOSE = 1
NB_CLASSES = 10   # number of outputs = number of digits
N_HIDDEN = 128
VALIDATION_SPLIT=0.2 # how much TRAIN is reserved for VALIDATION
DROPOUT = 0.3

#The hyperparameters & their values to be tested are stored in aspecial type
HP_NUM_UNITS = hp.HParam('num_units', hp.Discrete([128, 256, 512]))
HP_DROPOUT = hp.HParam('dropout', hp.RealInterval(0.1, 0.3))
HP_OPTIMIZER = hp.HParam('optimizer', hp.Discrete(['adam', 'sgd', 'rmsprop']))
HP_BATCHSIZE = hp.HParam('batch_size', hp.Discrete([64, 128, 256, 512]))

#Settinf the Metric to RMSE
#METRIC_RMSE = 'RootMeanSquaredError'
METRIC_RMSE = 'accuracy'

#Clear any logs from previous runs
#!rm -rf ./logs/

#A function that trains and validates the model and returns the rmse
def train_test_model(hparams):
#Keras sequential model with Hyperparameters passed from the argument
    model = tf.keras.models.Sequential()
    model.add(keras.layers.Dense(hparams[HP_NUM_UNITS],
            input_shape=(RESHAPED,),
            name='dense_layer', activation='relu'))
    model.add(keras.layers.Dropout(hparams[HP_DROPOUT]))
    model.add(keras.layers.Dense(hparams[HP_NUM_UNITS],
            name='dense_layer_2', activation='relu'))
    model.add(keras.layers.Dropout(hparams[HP_DROPOUT]))
    model.add(keras.layers.Dense(NB_CLASSES,
            name='dense_layer_3', activation='softmax'))
# summary of the model
    model.summary()

#Compiling the model
    model.compile(
            optimizer=hparams[HP_OPTIMIZER],
            loss='categorical_crossentropy',
            metrics=['accuracy']
    )

#Training the network
    model.fit(X_train, Y_train,
        batch_size=hparams[HP_BATCHSIZE], epochs=EPOCHS,
        verbose=VERBOSE, validation_split=VALIDATION_SPLIT)

    test_loss, test_acc = model.evaluate(X_test, Y_test)
    return test_acc

#A function to log the training process
def run(run_dir, hparams):
    with tf.summary.create_file_writer(run_dir).as_default():
        hp.hparams(hparams)
        test_acc = train_test_model(hparams)
        tf.summary.scalar(METRIC_RMSE, test_acc, step=10)

# loading MNIST dataset
# verify
# the split between train and test is 60,000, and 10,000 respectly
# one-hot is automatically applied
mnist = keras.datasets.mnist
(X_train, Y_train), (X_test, Y_test) = mnist.load_data()

#X_train is 60000 rows of 28x28 values --> reshaped in 60000 x 784
RESHAPED = 784
#
X_train = X_train.reshape(60000, RESHAPED)
X_test = X_test.reshape(10000, RESHAPED)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')

#normalize in [0,1]
X_train, X_test = X_train / 255.0, X_test / 255.0
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')

#one-hot
Y_train = tf.keras.utils.to_categorical(Y_train, NB_CLASSES)
Y_test = tf.keras.utils.to_categorical(Y_test, NB_CLASSES)

# Training the model for each combination of the hyperparameters.

#A unique number for each training session
session_num = 0

#Nested for loop training with all possible  combinathon of hyperparameters
for num_units in HP_NUM_UNITS.domain.values:
    for dropout_rate in tf.linspace(HP_DROPOUT.domain.min_value,HP_DROPOUT.domain.max_value,3):
        for optimizer in HP_OPTIMIZER.domain.values:
            for batchsize in HP_BATCHSIZE.domain.values:
                hparams = {
                        HP_NUM_UNITS: num_units,
                        HP_DROPOUT: float("%.2f"%float(dropout_rate)), # float("%.2f"%float(dropout_rate)) limits the decimal palces to 2
                        HP_OPTIMIZER: optimizer,
                        HP_BATCHSIZE: batchsize,
                    }
                run_name = "run-%d" % session_num
                print('--- Starting trial: %s' % run_name)
                print({h.name: hparams[h] for h in hparams})
                run('logs/hparam_tuning/' + run_name, hparams)
                session_num += 1

# making prediction
#predictions = model.predict(X_test)


import pandas as pd
import matplotlib.pyplot as plt

def get_winning_metrics(file_name):
    '''
    Get two dataframes: winners by language, and winners by country.
    '''

    winning_df = pd.read_csv(file_name)
    winning_df['Counter'] = [1 for i in range(len(winning_df.index))]

    metrics_language = winning_df.groupby(['SongLanguage']).Counter.sum().reset_index()

    metrics_country = winning_df.groupby(['Winner']).Counter.sum().reset_index()

    return [metrics_language.sort_values(by=['Counter'], ascending=False), metrics_country.sort_values(by=['Counter'], ascending=False)]

def plot_results(language_winners, winners):
    '''
    Plot the results of the language analysis.
    '''
    colors = ['#a8acc4', '#65ecfb', '#e190f7', '#335d6a', '#5496a8', '#d3d3a1', '#4c2c54', '#0c5484']

    x = language_winners['Counter']
    labels = language_winners['SongLanguage']
    x_new, labels_new = [], []

    for elem, label in zip(x, labels):
        if label != 'None':
            x_new.append(elem)
            labels_new.append(label)

    plt.title('Song languages by number of wins')
    plt.pie(x_new, labels=labels_new, colors=colors)
    plt.show()

    winners = winners.dropna()
    winners.plot(kind='bar',x='Winner', y='Counter', color='#a8acc4')
    plt.show()

if __name__ == '__main__':
    path = 'data/eurovision_winners.csv'
    language_winners, winners = get_winning_metrics(path)

    plot_results(language_winners, winners)


import random
import datetime

def run():

    '''Выполняем первое задание'''
    my_list_1 = [2, 5, 8, 2, 12, 12, 4]
    my_list_2 = [2, 7, 12, 3]

    for i in my_list_2:
        while i in my_list_1:
            my_list_1.remove(i)

    print(my_list_1)

    '''Выполняем второе задание'''
    date = datetime.date(random.randint(datetime.MINYEAR,datetime.MAXYEAR),random.randint(1,12),1)
    date += datetime.timedelta(random.randint(1,31))
    monthes = ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августв", "сентбря", "октября", "нобря", "декабря"]
    days = ['один','два','три','четыре','пять','шесть','семь','восемь','девять','десять','одиннадцать','двенадцать','тринадцать','четырнадцать','пятнадцать'
            'шестнадцать','семнадцать','восемнадцать','девятнадцать','двадцать','двадцать один','двадцать два','двадцать три','двадцать четыре'
            'двадцать пять','двадцать шесть','двадцать семь','двадцать восемь','двадцать девять','тридцать','тридцать один']
    date_reform = f'{days[date.day-1]} {monthes[date.month-1]} {date.year} года'
    print(date_reform)

    '''Выполняем третье задание'''
    first_list = []
    for i in range(1, random.randint(2,40)):
        first_list.append(random.randint(1,15))
    result = list(set(first_list))
    """for i in first_list:
        if i not in result:
            result.append(i)"""

    print(f'Оригинальный список\n{first_list}\n\nПосле удаления дубликатов\n{result}')


import torch
import random
import numpy as np

def get_random_sample(dataset):
    rnd_idx = random.randint(0, len(dataset) - 1)
    rnd_image, rnd_target = dataset.get_sample(rnd_idx)
    return rnd_image, rnd_target

def rand_bbox(size, lam):
    if len(size) == 4:
        W = size[2]
        H = size[3]
    elif len(size) == 3:
        W = size[1]
        H = size[2]
    elif len(size) == 2:
        W = size[0]
        H = size[1]
    else:
        raise Exception

    cut_rat = np.sqrt(1. - lam)
    cut_w = np.int(W * cut_rat)
    cut_h = np.int(H * cut_rat)

    # uniform
    cx = np.random.randint(W)
    cy = np.random.randint(H)

    bbx1 = np.clip(cx - cut_w // 2, 0, W)
    bby1 = np.clip(cy - cut_h // 2, 0, H)
    bbx2 = np.clip(cx + cut_w // 2, 0, W)
    bby2 = np.clip(cy + cut_h // 2, 0, H)

    return bbx1, bby1, bbx2, bby2

class CutMix:
    def __init__(self, beta=1.0):
        self.beta = beta

    def __call__(self, dataset, image, target):
        lam = np.random.beta(self.beta, self.beta)
        rnd_image, rnd_target = get_random_sample(dataset)

        bbx1, bby1, bbx2, bby2 = rand_bbox(image.shape, lam)
        if len(image.shape) == 2:
            image[bbx1:bbx2, bby1:bby2] = rnd_image[bbx1:bbx2, bby1:bby2]
        else:
            image[:, bbx1:bbx2, bby1:bby2] = rnd_image[:, bbx1:bbx2, bby1:bby2]
        lam = 1 - ((bbx2 - bbx1) * (bby2 - bby1)
                   / (image.shape[-1] * image.shape[-2]))

        new_target = []
        for trg, rnd_trg in zip(target, rnd_target):
            new_trg = trg, rnd_trg, torch.tensor(lam, dtype=torch.float32)
            new_target.append(new_trg)
        target = new_target

        return image, target

class RandomMixer:
    def __init__(self, mixers, p=None):
        self.mixers = mixers
        self.p = p

    def __call__(self, dataset, image, target):
        mixer = np.random.choice(self.mixers, p=self.p)
        image, target = mixer(dataset, image, target)
        return image, target

class UseMixerWithProb:
    def __init__(self, mixer, prob=.5):
        self.mixer = mixer
        self.prob = prob

    def __call__(self, dataset, image, target):
        if random.random() < self.prob:
            return self.mixer(dataset, image, target)
        return image, target


#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Python CloudFlare-DDNS 自动更新脚本
# by hjh
#       ┏┓    ┏┓  + +
#      ┏┛┻━━━━┛┻┓ + +
#      ┃        ┃ + +
#      ┃   ━    ┃ + + + + +
#     ████━████ ┃ + + + + +
#      ┃        ┃ +
#      ┃   ┻    ┃
#      ┃        ┃ + +
#      ┗━┓    ┏━┛
#        ┃    ┃
#        ┃    ┃ + + + +
#        ┃    ┃ Codes are far away from bugs with the animal protecting
#        ┃    ┃ + 神兽保佑,代码bug
#        ┃    ┃
#        ┃    ┃ +
#        ┃    ┗━━━┓ + +
#        ┃        ┣┓
#        ┃       ┏┛
#        ┗┓┓┏━┳┓┏┛+ + + +
#         ┃┫┫ ┃┫┫
#         ┗┻┛ ┗┻┛+ + + +

try:
    # Python3加载外部库
    from urllib.request import urlopen
    from urllib.request import Request
    from urllib.error import URLError
    from urllib.error import HTTPError
    # 噜啦啦。。。
except ImportError:      #若加载错误，识别为Python2
    # Python2加载外部库
    from urllib2 import urlopen
    from urllib2 import Request
    from urllib2 import HTTPError
    from urllib2 import URLError

import json

config_file_name = '/usr/local/bin/cf-ddns.conf'   # 使用绝对路径加载配置文件

with open(config_file_name, 'r') as config_file:
    try:
        config = json.loads(config_file.read())
    except ValueError:
        print('错误：请检查配置文件！')
        exit(0)

if not config['user']['email'] or not config['user']['api_key']:
    print('错误：Cloudflare接口错误，请检查！')
    exit(0)

content_header = {'X-Auth-Email': config['user']['email'],
                  'X-Auth-Key': config['user']['api_key'],
                  'Content-type': 'application/json'}

base_url = 'https://api.cloudflare.com/client/v4/zones/'

public_ipv4 = None
public_ipv6 = None
ip_version = None

try:
    public_ipv4 = urlopen(Request(
        'http://ipv4.icanhazip.com/')).read().rstrip().decode('utf-8')
except URLError as e:
    print('未发现Ipv4地址，尝试寻找Ipv6地址')

try:
    public_ipv6 = urlopen(Request(
        'http://ipv6.icanhazip.com/')).read().rstrip().decode('utf-8')
except URLError as e:
    print('未发现Ipv6地址，将更新Ipv4地址')

if public_ipv4 is None and public_ipv4 is None:
    print('错误：未找到任何IP地址，请检查网络！')
    exit(0)

update = False

for domain in config['domains']:
    # 检查域名
    if not domain['name']:
        print('错误：此域名无效，请检查配置！')
        continue

    # 噜啦啦。。
    if not domain['id']:
        try:
            print(
                '咦？ "{0}" 的zone id不见了耶~嘿嘿'
                '，正在向CloudFlare获取'.format(domain['name']))
            zone_id_req = Request(base_url, headers=content_header)
            zone_id_resp = urlopen(zone_id_req)
            for d in json.loads(zone_id_resp.read().decode('utf-8'))['result']:
                if domain['name'] == d['name']:
                    domain['id'] = d['id']
                    print(' "{0}" 的zone id是'
                          ' {1}'.format(domain['name'], domain['id']))
        except HTTPError as e:
            print('错误：无法向CLoudFlare获取zone id {0}'.format(domain['name']))
            print('可能是你的cf-ddns.conf配置错误？也有可能是你的CloudFlare域名解析配置错误。。。')
            continue

    for host in domain['hosts']:
        fqdn = host['name'] + '.' + domain['name']

        if not host['name']:
            print('错误：没有找到解析记录，请检查你的CLoudFlare设置！')
            continue

        if not host['id']:
            print(
                '咦？ "{0}" 的host id不见了耶~嘿嘿'
                '，正在向CloudFlare获取'.format(fqdn))
            rec_id_req = Request(
                base_url + domain['id'] + '/dns_records/',
                headers=content_header)
            rec_id_resp = urlopen(rec_id_req)
            parsed_host_ids = json.loads(rec_id_resp.read().decode('utf-8'))
            for h in parsed_host_ids['result']:
                if fqdn == h['name']:
                    host['id'] = h['id']
                    print(' "{0}" 的host id是'
                          ' {1}'.format(fqdn, host['id']))

        for t in host['types']:
            if t not in ('A', 'AAAA'):
                print('错误：错误的域名解析记录类型，必须是A或AAAA，你的记录类型是: {0}'.format(t))
                continue
            elif t == 'A':
                if public_ipv4:
                    public_ip = public_ipv4
                    ip_version = 'ipv4'
                else:
                    print('未发现Ipv4地址，，因此无法添加A解析记录')
                    continue
            elif t == 'AAAA':
                if public_ipv6:
                    public_ip = public_ipv6
                    ip_version = 'ipv6'
                else:
                    print('没有找到Ipv6地址，因此无法添加AAAA解析记录')
                    continue

            # 若IP变化，更新IP解析
            if host[ip_version] != public_ip:
                try:
                    if not t:
                        raise Exception

                    data = json.dumps({
                        'id': host['id'],
                        'type': t,
                        'name': host['name'],
                        'content': public_ip
                    })
                    url_path = '{0}{1}{2}{3}'.format(base_url,
                                                     domain['id'],
                                                     '/dns_records/',
                                                     host['id'])
                    update_request = Request(
                        url_path,
                        data=data.encode('utf-8'),
                        headers=content_header)
                    update_request.get_method = lambda: 'PUT'
                    update_res_obj = json.loads(
                        urlopen(update_request).read().decode('utf-8'))
                    if update_res_obj['success']:
                        update = True
                        host[ip_version] = public_ip
                        print('更新成功 (type: {0}, fqdn: {1}'
                              ', ip: {2})'.format(t, fqdn, public_ip))
                except (Exception, HTTPError) as e:
                    print('哎？更新出错了，可能是网络问题？若多次出错，可能是你的CloudFlare API密钥错误哦！ (type: {0}, fqdn: {1}'
                          ', ip: {2})'.format(t, fqdn, public_ip))

if update:
    print('更新成功啦～')
    with open(config_file_name, 'w') as config_file:
        json.dump(config, config_file, indent=1, sort_keys=True)
else:
    print('IP地址未更换，无需更新～')
# 撸啦啦……皮一下很开森…


# -*- coding: utf-8 -*-
# @File : openai.py
# @Author : r.yang
# @Date : Wed Mar 15 17:18:05 2023
# @Description :

import requests

from icommit.prompt import Prompt

def ask(
    content: str,
    api_key: str,
    timeout: int = 30,
    model: str = 'gpt-3.5-turbo',
    proxy: str = '',
    sys_prompt: str = 'You are ChatGPT, a large language model trained by OpenAI. Respond conversationally',
):
    headers = {
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json',
    }

    data = {
        'model': model,
        'messages': [
            {'role': 'system', 'content': sys_prompt,},
            {'role': 'user', 'content': content},
        ],
        'user': 'user',
    }

    response = requests.post(
        'https://api.openai.com/v1/chat/completions',
        headers=headers,
        json=data,
        timeout=timeout,
        proxies={'http': proxy, 'https': proxy} if proxy else None,
    )

    response.raise_for_status()
    return response.json()['choices'][0]['message']['content'].lower().strip().strip('."')

def summarize(
    prompt: 'Prompt', **kwargs,
):
    return ask(prompt.summarize, **kwargs)

def classify(
    prompt: 'Prompt', **kwargs,
):
    return ask(prompt.classify, sys_prompt='you are a classifier', **kwargs).split(':')[0]


from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq

my_url = 'https://www.newegg.com/Product/ProductList.aspx?Submit=ENE&DEPA=0&Order=BESTMATCH&Description=virtual+reality&N=-1&isNodeId=1'
#opens connection and grabs page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
#html parser
page_soup = soup(page_html, "html.parser")

#grabs each product
containers = page_soup.findAll("div", {"class":"item-container"})
filename = "products.csv"
f = open(filename, "w")
headers = "brand, product_name\n"
f.write(headers)

for container in containers:
	brand = container.img["title"]
	title_container = container.findAll("a", {"class":"item-title"})
	product_name = title_container[0].text.strip()
	#price_container = container.findAll("li", {"class":"price-current"})
	#product_price = price_container[0].text.strip()

	print("brand: " + brand)
	print("product_name: " + product_name)
	#print("product_price: " + product_price)

	f.write(brand + "," + product_name.replace(",", "|") + "\n")
f.close()


"""
Yes, it is possible to extract the RGB value of the region in the bounding box.

Assuming you read the image with CV2, then the image is already represented as BGR. All you'd have to do is find a point in the bounding box and extract the BGR value of the point. Note I'm using BGR because that is how OpenCV reads images.

Using the bounding box vertices you used, just calculate a midpoint in the bounding box and extract the BGR value of that midpoint in the image.

# midpoint is ((y_max - y_min) // 2 + y_min, (x_max - x_min) // 2 + x_min)
point = ((70 - 45) // 2 + 45, (250 - 150) // 2 + 150)

b, g, r = image[point]
If the pixels in the bounding boxes have varying colors though, this method won't work. In that case, maybe you want to get the mean BGR values.

# image[y_min:y_max, x_min:x_max]
region = image[45:70, 150:250]

b, g, r = np.mean(region, axis=(0, 1))

INPUTS: https://stackoverflow.com/questions/53304188/how-to-find-rgb-value-of-a-bounded-region-in-an-image-using-python/53305160#53305160
http://marksolters.com/programming/2015/02/27/rgb-histograph.html
"""

import numpy as np
import matplotlib.pyplot as plt
import cv2

i=cv2.imread(r'C:\Users\DHAVAL\Desktop\71Icb3wd6DL._SL1500_.jpg')
im=cv2.resize(i,(1020,880))
#cv2.rectangle(im,(850,586),(840,580),(0,255,0),5)
op=cv2.rectangle(im,(534,56),(510,158),(0,255,0),3)
kk=cv2.imwrite("doc.jpg",op)
#cv2.imshow("image",kk)
#cv2.waitKey(0)
# region = kk[45:70,150:250]

# b, g, r = np.mean(region, axis=(0, 1)

point = (( 158- 56) // 2 + 45, (534-510) // 2 + 510)

b, g, r = kk[point]

print(b)
print(g)
print(r)


"""empty message

Revision ID: da73f02eb0e6
Revises: c018b2059243
Create Date: 2020-10-22 23:24:36.700413

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = 'da73f02eb0e6'
down_revision = 'c018b2059243'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('comment', 'book_id',
               existing_type=mysql.INTEGER(),
               nullable=True)
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('comment', 'book_id',
               existing_type=mysql.INTEGER(),
               nullable=False)
    # ### end Alembic commands ###


#!/usr/bin/python

###
 # Copyright (c) 2016 Nishant Das Patnaik.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
 #  http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
###

import os, sys, re, argparse, codecs, subprocess, pwd, glob, shutil, time, zipfile, traceback, plistlib
from termcolor import colored

print("""
     ___      .______   .______   .___  ___.   ______   .__   __.
    /   \     |   _  \  |   _  \  |   \/   |  /  __  \  |  \ |  |
   /  ^  \    |  |_)  | |  |_)  | |  \  /  | |  |  |  | |   \|  |
  /  /_\  \   |   ___/  |   ___/  |  |\/|  | |  |  |  | |  . `  |
 /  _____  \  |  |      |  |      |  |  |  | |  `--'  | |  |\   |
/__/     \__\ | _|      | _|      |__|  |__|  \______/  |__| \__|
                        github.com/dpnishant

""")

parser = argparse.ArgumentParser()
parser.add_argument('-ipa', action='store', dest='ipa_path', default='',
                                        help='''(Absolute) Path to IPA''')
parser.add_argument('-mobileprovision', action='store', dest='mobileprovision_path', default='',
                                        help='''(Absolute) Path to embedded.mobileprovision (OPTIONAL)''')
parser.add_argument('-identity', action='store', dest='dev_identity', default='',
                                        help='''Developer Identity Hash (OPTIONAL)''')
parser.add_argument('-uuid', action='store', dest='uuid', default='',
                                        help='''Device UUID (OPTIONAL)''')
parser.add_argument('-v', action='version', version='AppMon IPA Installer v0.1, Copyright 2016 Nishant Das Patnaik')

if len(sys.argv) < 2:
    parser.print_help()
    sys.exit(1)

if not os.path.isdir(os.path.join(os.getcwd(), "apps")):
    os.makedirs(os.path.join(os.getcwd(), "apps"))

def deviceError():
    print("%s" % colored("Error: Is the device connected over USB?", "red", attrs=["bold"]))
    sys.exit(255)

def getDeveloperId():
    for id in subprocess.check_output(["node", "node-applesign/bin/ipa-resign.js", "-L"]).split("\n"):
        if "iPhone Developer:" in id:
            return id.split(" ")[0]
        else:
            print("No \"iPhone Developer\" identity found!")
            devID = input("Enter \"iPhone Developer\" Identity Hash: ")
            return devID

def getMobileProvisionFile():
    PATH = "/Users/%s/Library/Developer/Xcode/DerivedData" % pwd.getpwuid(os.getuid())[0]
    mobileprovision_path = [os.path.join(dp, f) for dp, dn, filenames in os.walk(PATH) for f in filenames if os.path.splitext(f)[1] == '.mobileprovision']
    if len(mobileprovision_path) == 1:
        mobileprovision_path = mobileprovision_path[0]
        if not os.path.isfile(mobileprovision_path):
            mobileprovision_path = input('Provide the path to "embedded.mobileprovision" file: ')
            return mobileprovision_path
    elif len(mobileprovision_path) > 1:
        for path in mobileprovision_path:
            print("%s: %s" % (str(mobileprovision_path.index(path)), path))
        path_index = input('Choose Provision file for IPA re-signing? (e.g. 0, 1...): ')
        mobileprovision_path = mobileprovision_path[int(path_index)]
        return mobileprovision_path
    else:
        mobileprovision_path = input('Provide the absolute path to "embedded.mobileprovision" file: ')
        return mobileprovision_path

def getMachOExecutable(app_path):
    try:
        plist_path = os.path.join(app_path, "Info.plist")
        plist = plistlib.readPlist(plist_path)
        executable = plist["CFBundleExecutable"]
        return os.path.join(app_path, executable)
    except Exception as _error:
        try:
            filenames = os.listdir(app_path)
            for filename in filenames:
                path = os.path.join(app_path, filename)
                if not os.path.isdir(path):
                    output = subprocess.check_output(['file', path])
                    if "Mach-O" in output:
                        output = output.split(":")[0]
                        break
            return os.path.join(app_path, output)
        except Exception as __error:
            print(traceback.print_exc())

def getDeviceUUID():
    try:
        print("[+] Trying to detect device...")
        uuid = subprocess.check_output(["sudo", "ideviceinfo", "-s"]).split("UniqueDeviceID: ")[1].split("\n")[0]
        device_conn = subprocess.check_output(["sudo", "ios-deploy", "-i", uuid, "--no-wifi", "-c"])
        if "Found %s (" % (uuid) in device_conn:
            print("[+] Found %s connected through USB." % colored(device_conn.split("Found")[1].strip().split(" connected through USB.")[0], "green", attrs=["bold"]))
            time.sleep(1)
        else:
            print(uuid, device_conn)
            deviceError()
    except Exception as e:
            print(str(e))
            deviceError()

    return uuid

results = parser.parse_args()
ipa_path = results.ipa_path

if not results.mobileprovision_path:
    mobileprovision_path = getMobileProvisionFile()
else:
    mobileprovision_path = results.mobileprovision_path

if not results.uuid:
    uuid = getDeviceUUID()
else:
    uuid = results.uuid

try:
    if len(results.dev_identity) == 40:
        dev_identity = results.dev_identity
    else:
        dev_identity = getDeveloperId()
except AttributeError:
    dev_identity = getDeveloperId()

work_dir = "/tmp/appmon_ipa/"
unzip_filename = os.path.basename(ipa_path).split(".")[0]
unzip_filepath = os.path.join(work_dir, unzip_filename)
zip_filepath = os.path.join(work_dir, "%s.zip" % unzip_filename)
optool_path = "optool/bin/optool"
injected_zip_filename = "%s-injected.zip" % unzip_filename
injected_zip_filepath = os.path.join(work_dir, injected_zip_filename)
injected_ipa_filename = "%s-injected.ipa" % unzip_filename
injected_ipa_filepath = os.path.join(work_dir, injected_ipa_filename)
iparesign_path = "node-applesign/bin/ipa-resign.js"
resign_name = "%s-injected-resigned" % unzip_filename
resigned_ipa_name = "%s.ipa" % resign_name
extracted_resigned_path = os.path.join(os.getcwd(), "apps", resign_name)
gadget_name = "FridaGadget.dylib"
gadget_path = str(os.path.join(os.getcwd(), gadget_name))

if os.path.isdir(work_dir):
    shutil.rmtree(work_dir)

os.makedirs(work_dir)
subprocess.call(["cp", ipa_path, zip_filepath])
print("[+] Unpacking IPA...")
subprocess.check_output(["unzip", zip_filepath, "-d", unzip_filepath])
payload_path = os.path.join(os.path.abspath(unzip_filepath), "Payload/")

if os.listdir(payload_path)[0].endswith(".app"):
    app_name = os.listdir(payload_path)[0]
    app_path = os.path.join(payload_path, app_name)
    _CodeSignature_path = os.path.join(app_path, "_CodeSignature/")
    executable_filepath = getMachOExecutable(app_path)
    #print executable_filepath
    injected_dylib_path = os.path.join(app_path, "FridaGadget.dylib")

subprocess.check_output(["rm", "-rf", _CodeSignature_path])
subprocess.check_output(["chmod", "755", "FridaGadget.dylib"])
subprocess.check_output(["cp", gadget_path, app_path])
print("[+] Injecting DYLIB...")
subprocess.check_output([optool_path, "install", "-c", "load", "-p", "@executable_path/FridaGadget.dylib", "-t", executable_filepath])
print("[+] Code-signing...")
subprocess.check_output(["codesign", "-fs", 'iPhone Developer', injected_dylib_path])
subprocess.check_output(["codesign", "-fs", 'iPhone Developer', app_path])
subprocess.check_output(["find", unzip_filepath, "-name", '".DS_Store"', "-type", "f", "-delete"])
shutil.make_archive(injected_zip_filepath.strip(".zip"), 'zip', unzip_filepath)
os.rename(injected_zip_filepath, injected_ipa_filepath)
shutil.copy(injected_ipa_filepath, os.getcwd())
subprocess.check_output(["node", iparesign_path, "--without-watchapp", "--identity", dev_identity, "--mobileprovision", mobileprovision_path, injected_ipa_filename])
shutil.copy(os.path.join(os.getcwd(), resigned_ipa_name), os.path.join(os.getcwd(), "%s.zip" % resign_name))
subprocess.check_output(["unzip", os.path.join(os.getcwd(), resigned_ipa_name), "-d", extracted_resigned_path])
subprocess.check_output(["rm", "-rf", work_dir])
subprocess.check_output(["rm", "-rf", os.path.join(os.getcwd(), "%s.zip" % resign_name)])
subprocess.check_output(["rm", "-rf", os.path.join(os.getcwd(), injected_ipa_filename)])
subprocess.check_output(["mv", "./%s" % resigned_ipa_name, "apps/"])
#subprocess.call(["sudo", "ideviceinstaller", "-u", uuid, "-i", "%s/Payload/%s" % (extracted_resigned_path, app_name)])
print("[+] Installing IPA...")
subprocess.check_output(["sudo", "ios-deploy", "-v", "--no-wifi", "-i", uuid, "-b", "%s/Payload/%s" % (extracted_resigned_path, app_name)])
#print(chr(27) + "[2J")
time.sleep(2)
print("%s" % colored("----------------HELP----------------", "green", attrs=["bold"]))
print('[+] Wait for "%s", on the debugger console to initialize' % colored("60 seconds", "red", attrs=["bold"]))
time.sleep(1)
print('[+] Keep the debugger running to continue using the app. To quit type "%s", in the debugger console.' % colored("quit", attrs=["bold"]))
time.sleep(2)
print('[+] The app will remain suspended until you run, (in a different terminal window/tab), \n%s' % colored("frida -U Gadget", "red", attrs=["bold"]))
time.sleep(2)
print("[+] Generating launch script...")
message = """#!/bin/sh
# %s app launcher script generated by AppMon
# http://dpnishant.github.com/appmon

sudo ios-deploy -d --no-wifi -i %s --noinstall -b %s/Payload/%s
""" % (unzip_filename, uuid, extracted_resigned_path, app_name)
launcher_path = 'sh ./%s/launch_%s.sh' % (resign_name, unzip_filename)
with codecs.open('%s/launch_%s.sh' % (extracted_resigned_path, unzip_filename), 'w', 'utf-8') as f:
    f.write(message)

time.sleep(2)

print('NOTE: To launch the installed app, in future, run: \n%s\n' % colored(launcher_path, "blue", attrs=["bold"]))
print("%s" % colored("------------------------------------", "green", attrs=["bold"]))
time.sleep(2)
print(colored("[+] Starting app..."))
time.sleep(2)
subprocess.call(["sudo", "ios-deploy", "-v", "--no-wifi", "-i", uuid, "--noinstall", "-b", "%s/Payload/%s" % (extracted_resigned_path, app_name)])
sys.exit(0)


# logistics_dic = {
#     '고양1': {
#         '발주건수': 3,
#         '발주수량': [8, 22, 20],
#         '발주아이템': ['말랑하니 오가닉 속싸개_엘라스틴_그레이도트M', '말랑하니 오가닉속싸개_엘라스틴_캐럿핑크S', '말랑하니 오가닉속싸개_엘라스틴_캐럿핑크M'],
#         '발주번호': [19351878, 19351878, 19346395],
#     }
# }

# print(logistics_dic.get(''))

# print(logistics_dic.get('고양2', 'NOTHING'))
# print(logistics_dic.get('고양1').get('발주번호')[2])
# logistics_dic = {}
# for i in range(city_numbers):
#     logistics_dic[city_series[i]] = df[cities == city_series[i]].shape[0]

# is_goyang1 = df[df['물류센터'] == '덕평1']
# print(is_goyang1.shape[0])
# # print(type(is_goyang1.shape[1]))
# for i in range(is_goyang1.shape[1]):
#     order_number.append(is_goyang1.iloc[i].loc['발주번호'])
#     order_quantity.append(is_goyang1.iloc[i].loc['발주수량'])
#     order_item.append(is_goyang1.iloc[i].loc['SKU 이름'])
# print("덕평1 발주번호: ", order_number)
# print("덕평1 발주수량: ", order_quantity)
# print("덕평1 발주아이템: ", order_item)

import datetime
import openpyxl
from openpyxl.styles import Alignment, Font, PatternFill
import pandas as pd
import city_info as ci

df = pd.read_csv(
    '/Users/martinkim/GITHUB/00_Automated System/02_Logistics-team/logistics_tracking-number/PO_SKU_LIST_20200904150707.csv')
order_count = df.shape[0]
cities = df['물류센터']
city_series = cities.drop_duplicates()
city_series.reset_index(drop=True, inplace=True)
city_numbers = len(city_series)
order_info = [[0 for col in range(2)] for row in range(city_numbers)]
for i in range(city_numbers):
    order_info[i][0] = city_series[i]
    order_info[i][1] = df[cities == city_series[i]].shape[0]

print(
    f'총 발주 물량은 {order_count}개이며, 총 {city_numbers}군데의 도시에서 {order_info}이다')

# CREATE EXCEL
today_date = datetime.datetime.now().strftime('%Y%m%d')

wb = openpyxl.Workbook()
ws = wb.active
# Initialize
ws.title = today_date + '입고예정'
ws['A1'] = '이름'
ws['B1'] = '전화1'
ws['C1'] = '전화2'
ws['D1'] = '우편번호'
ws['E1'] = '주소'
ws['F1'] = '수량'
ws['G1'] = '품목'
ws['H1'] = '배송시요구사항'
ws['I1'] = '사이트'
ws['J1'] = '순번'
ws['K1'] = '주문번호'
ws['L1'] = '운송장번호'
ws['M1'] = '받는분'
# Make cells Bold / Aligned / Bg-colored
cell_list = ['A1', 'B1', 'C1', 'D1', 'E1', 'F1',
             'G1', 'H1', 'I1', 'J1', 'K1', 'L1', 'M1']
for i in range(len(cell_list)):
    ws[cell_list[i]].font = Font(bold=True, color='FFFFFF')
    ws[cell_list[i]].fill = PatternFill(
        fgColor='8B0000', patternType='solid')
    ws[cell_list[i]].alignment = Alignment(
        horizontal='center', vertical='center')
# Differentiate two columns for future input
ws['L1'].fill = PatternFill(fgColor='ADD8E6', patternType='solid')
ws['M1'].fill = PatternFill(fgColor='ADD8E6', patternType='solid')

# INPUT VALUE INTO EXCEL
order_quantity = []
order_number = []
order_item = []
start = 2

for i in range(city_numbers):
    city = df[df['물류센터'] == order_info[i][0]]

    for j in range(order_info[i][1]):
        order_quantity.append(city.iloc[j].loc['발주수량'])
        order_item.append(city.iloc[j].loc['SKU 이름'])
        order_number.append(city.iloc[j].loc['발주번호'])

    print(f'{order_info[i][0]} 발주수량: {order_quantity}')
    print(f'{order_info[i][0]} 발주아이템: {order_item}')
    print(f'{order_info[i][0]} 발주번호: {order_number}')

    for k in range(order_info[i][1]):
        if ws['A'+str(start)].value != None:
            while (ws['A'+str(start)].value != None):
                start += 1
        ws['A'+str(start)] = order_info[i][0]
        ws['F'+str(start)] = order_quantity[k]
        ws['G'+str(start)] = order_item[k]
        ws['H'+str(start)] = "발주번호: " + str(order_number[k])
        ws['I'+str(start)] = '쿠팡'

        if ws['A'+str(start)].value == '고양1':
            ws['B'+str(start)] = ci.GOYANG1.get('phone1')
            ws['C'+str(start)] = ci.GOYANG1.get('phone2')
            ws['D'+str(start)] = ci.GOYANG1.get('zip')
            ws['E'+str(start)] = ci.GOYANG1.get('address')
        elif ws['A'+str(start)].value == '광주':
            ws['B'+str(start)] = ci.GWANGJU.get('phone1')
            ws['C'+str(start)] = ci.GWANGJU.get('phone2')
            ws['D'+str(start)] = ci.GWANGJU.get('zip')
            ws['E'+str(start)] = ci.GWANGJU.get('address')
        elif ws['A'+str(start)].value == '대구2':
            ws['B'+str(start)] = ci.DAEGU2.get('phone1')
            ws['C'+str(start)] = ci.DAEGU2.get('phone2')
            ws['D'+str(start)] = ci.DAEGU2.get('zip')
            ws['E'+str(start)] = ci.DAEGU2.get('address')
        elif ws['A'+str(start)].value == '덕평1':
            ws['B'+str(start)] = ci.DEOKPYEONG1.get('phone1')
            ws['C'+str(start)] = ci.DEOKPYEONG1.get('phone2')
            ws['D'+str(start)] = ci.DEOKPYEONG1.get('zip')
            ws['E'+str(start)] = ci.DEOKPYEONG1.get('address')
        elif ws['A'+str(start)].value == '동탄1':
            ws['B'+str(start)] = ci.DONGTAN1.get('phone1')
            ws['C'+str(start)] = ci.DONGTAN1.get('phone2')
            ws['D'+str(start)] = ci.DONGTAN1.get('zip')
            ws['E'+str(start)] = ci.DONGTAN1.get('address')
        elif ws['A'+str(start)].value == '마장1':
            ws['B'+str(start)] = ci.MAJANG.get('phone1')
            ws['C'+str(start)] = ci.MAJANG.get('phone2')
            ws['D'+str(start)] = ci.MAJANG.get('zip')
            ws['E'+str(start)] = ci.MAJANG.get('address')
        elif ws['A'+str(start)].value == '목천1':
            ws['B'+str(start)] = ci.MOKCHEON1.get('phone1')
            ws['C'+str(start)] = ci.MOKCHEON1.get('phone2')
            ws['D'+str(start)] = ci.MOKCHEON1.get('zip')
            ws['E'+str(start)] = ci.MOKCHEON1.get('address')
        elif ws['A'+str(start)].value == '부천1':
            ws['B'+str(start)] = ci.BUCHEON1.get('phone1')
            ws['C'+str(start)] = ci.BUCHEON1.get('phone2')
            ws['D'+str(start)] = ci.BUCHEON1.get('zip')
            ws['E'+str(start)] = ci.BUCHEON1.get('address')
        elif ws['A'+str(start)].value == '서울':
            ws['B'+str(start)] = ci.SEOUL.get('phone1')
            ws['C'+str(start)] = ci.SEOUL.get('phone2')
            ws['D'+str(start)] = ci.SEOUL.get('zip')
            ws['E'+str(start)] = ci.SEOUL.get('address')
        elif ws['A'+str(start)].value == '안성4':
            ws['B'+str(start)] = ci.ANSEONG4.get('phone1')
            ws['C'+str(start)] = ci.ANSEONG4.get('phone2')
            ws['D'+str(start)] = ci.ANSEONG4.get('zip')
            ws['E'+str(start)] = ci.ANSEONG4.get('address')
        elif ws['A'+str(start)].value == '양산1':
            ws['B'+str(start)] = ci.YANGSAN1.get('phone1')
            ws['C'+str(start)] = ci.YANGSAN1.get('phone2')
            ws['D'+str(start)] = ci.YANGSAN1.get('zip')
            ws['E'+str(start)] = ci.YANGSAN1.get('address')
        elif ws['A'+str(start)].value == '인천1':
            ws['B'+str(start)] = ci.INCHEON1.get('phone1')
            ws['C'+str(start)] = ci.INCHEON1.get('phone2')
            ws['D'+str(start)] = ci.INCHEON1.get('zip')
            ws['E'+str(start)] = ci.INCHEON1.get('address')
        elif ws['A'+str(start)].value == '인천4':
            ws['B'+str(start)] = ci.INCHEON4.get('phone1')
            ws['C'+str(start)] = ci.INCHEON4.get('phone2')
            ws['D'+str(start)] = ci.INCHEON4.get('zip')
            ws['E'+str(start)] = ci.INCHEON4.get('address')
        elif ws['A'+str(start)].value == '인천5':
            ws['B'+str(start)] = ci.INCHEON5.get('phone1')
            ws['C'+str(start)] = ci.INCHEON5.get('phone2')
            ws['D'+str(start)] = ci.INCHEON5.get('zip')
            ws['E'+str(start)] = ci.INCHEON5.get('address')
        elif ws['A'+str(start)].value == '천안':
            ws['B'+str(start)] = ci.CHOENAN.get('phone1')
            ws['C'+str(start)] = ci.CHOENAN.get('phone2')
            ws['D'+str(start)] = ci.CHOENAN.get('zip')
            ws['E'+str(start)] = ci.CHOENAN.get('address')
        elif ws['A'+str(start)].value == '평택1':
            ws['B'+str(start)] = ci.PYOENGTAEK1.get('phone1')
            ws['C'+str(start)] = ci.PYOENGTAEK1.get('phone2')
            ws['D'+str(start)] = ci.PYOENGTAEK1.get('zip')
            ws['E'+str(start)] = ci.PYOENGTAEK1.get('address')
        elif ws['A'+str(start)].value == '호법':
            ws['B'+str(start)] = ci.HOBEOP.get('phone1')
            ws['C'+str(start)] = ci.HOBEOP.get('phone2')
            ws['D'+str(start)] = ci.HOBEOP.get('zip')
            ws['E'+str(start)] = ci.HOBEOP.get('address')

    order_number.clear()
    order_quantity.clear()
    order_item.clear()

wb.save('쿠팡 주소록-정리_' + today_date + '.xlsx')


from ml_modeling import ml_modeling
from PrepareData import PrepareData
import pandas as pd
import numpy as np
from sklearn.inspection import plot_partial_dependence
from sklearn.inspection import partial_dependence

def get_PDP(model_name,model_data,dummyVar,ConVar,DepVar,col_to_var_base,test_size):

    X_train, X_test, y_train, y_test, X_test_column_order,Y_list = PrepareData(model_data,dummyVar,ConVar,DepVar,
                                                                           col_to_var_base,
                                                                           test_size)

    clf = ml_modeling(model_name,X_train, X_test, y_train, y_test)
    feature = ConVar

    for i in range(len(feature)):
        feature_idx = X_test_column_order[feature[i]]
        lgb_PP_value = partial_dependence(clf,
                                          X_train,
                                          feature_idx,
                                          grid_resolution=100,kind = "average")
        orgvalue = lgb_PP_value['values'][0]
        pred_ave = lgb_PP_value['average'][0]
        v1name = model_name + '_' + feature[i] + "_org_value"
        v2name = model_name + '_' + feature[i] + "_pred_ave"

#         print(pred_ave.shape)
#         print(orgvalue.shape)
        df = pd.DataFrame(data = {v1name:orgvalue, v2name:pred_ave})
        if i == 0:
            partial_dependence_rs = df
        else:
            partial_dependence_rs = pd.concat([partial_dependence_rs,df],axis = 1)

    return(partial_dependence_rs)


#! -*-coding:utf-8-*-
'''
date:2017-04-25
author:liuzesi
info:

'''

from datetime import datetime,date
import sys,subprocess,os,time
sys.path.append('/ngbss/credit/practice/code')
from src.utils.logger.logger import Log

class gprsStopAT(object):
	"""docstring for gprsStopAT"""
	def __init__(self):
		super(gprsStopAT, self).__init__()
		self.logger=Log('gprsStop').getLogger( )
		self.binpath='/ngbss/credit/bin/'
		self._prov=''

	def setProv(self,_prov):
		self._prov = _prov

	def doProcess(self):
		self.logger.info('gprsStop begin')
		#log='sdfasdfasdfasdfasdfasdfasd'
		for i in range(10):
			t=datetime.now()
			self.logger.debug(t)
			tt=datetime.now()-t
			self.logger.debug(tt)

		#subprocess.Popen(self.binpath+'gprsStop -c0 -p'+self._prov,shell=True)
		self.logger.info('gprsStop end')

a=gprsStopAT()
a.setProv('11')
a.doProcess()


import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import traci

from collections import defaultdict
from seal.sumo.env import SumoEnv
from seal.sumo.kernel.kernel import SumoKernel
from seal.sumo.utils.random_routes import generate_random_routes
from os.path import join
from typing import Tuple

def main() -> pd.DataFrame:
    env = SumoEnv(config={
        "gui": False,
        "net-file": join("configs", "two_inter", "two_inter.net.xml"),
        "rand_route_args": {
            "n_vehicles": (100, 500),
            "end_time": 300
        }
    })

    tmp_data = defaultdict(list)
    total_reward = defaultdict(list)
    n_episodes = 1

    for ep in range(n_episodes):
        env.reset()
        done, step = False, 0
        last_reward = defaultdict(float)

        while not done:
            action = env.action_space.sample()
            obs, rewards, done, info = env.step(action)

            for tls_id, reward in rewards.items():
                total_reward["tls_id"].append(tls_id)
                total_reward["reward"].append(reward)
                total_reward["step"].append(step)
                total_reward["cumulative"].append(reward + last_reward[tls_id])
                last_reward[tls_id] += reward
            step += 1

    env.close()

    # Do a simple lineplot of the cumulative reward taken over time.
    sns.set_style("ticks")
    total_reward = pd.DataFrame.from_dict(total_reward)
    sns.lineplot(
        x="step",
        y="cumulative",
        style="tls_id",
        hue="tls_id",
        data=total_reward
    )
    plt.show()

    return total_reward

if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
import random

from apps.person_info.models import RequestLogger
from django.core.urlresolvers import reverse
from django.test import TestCase, Client

class MiddleWareLoggerViewTest(TestCase):
    """Middleware test"""

    def setUp(self):
        self.client = Client()

    def test_request_logger(self):
        """test status code"""
        response = self.client.get(reverse('request_logger'))
        self.assertEqual(response.status_code, 200)

    def test_request_logger_html(self):
        """test template render"""
        html = '42 Coffee Cups Test Assignment'
        response = self.client.get(reverse('request_logger'))
        self.assertTrue(html in response.content)
        template_name = 'person_info/request_logger.html'
        self.assertTemplateUsed(response, template_name)

    def test_middleware_logger(self):
        """test add any data to db"""
        RequestLogger.objects.all().delete()
        self.client.get(reverse('request_logger'))
        self.assertEqual(RequestLogger.objects.all().count(), 1)
        last_request = RequestLogger.objects.last()
        self.assertEqual(last_request.full_path, '/request_logger/')
        self.assertEqual(last_request.request_method, 'GET')
        self.assertEqual(last_request.ip_addr, '127.0.0.1')
        # test priority field
        self.assertEqual(last_request.priority, 0)

    def test_template_limit(self):
        """Test for correct response"""
        for i in range(10):
            self.client.get(reverse('index'))
            self.client.get(reverse('request_logger'))
        requests = RequestLogger.objects.all()
        self.assertEqual(requests.count(), 20)
        # elements per page <= 10
        response = self.client.get(reverse('request_logger'))
        requests_count = response.context['requests'].count()
        self.assertEqual(requests_count, 10)

    def test_priority_field(self):
        """Test priority field"""
        for i in range(15):
            self.client.get(reverse('request_logger'))
        for request in RequestLogger.objects.all():
            request.priority = (random.randint(0, 4))
            request.save()
        response = self.client.get(reverse('request_logger'),
                                   {'order_by': '1'})
        requests = response.context['requests']
        priority_list = []
        for i in requests.all():
            priority_list.append(i.priority)
        self.assertEqual(priority_list, sorted(priority_list))


from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time

# Tentukan jalur ke ChromeDriver
chromedriver_path = "C:/path/to/chromedriver.exe"

# Inisialisasi service Chrome
service = Service(executable_path=chromedriver_path)

# Buat opsi Chrome
options = Options()
# Tambahkan opsi tambahan jika diperlukan
options.add_argument("--start-maximized")  # Contoh: maksimalkan jendela browser saat dibuka

# Inisialisasi WebDriver Chrome dengan service dan opsi
driver = webdriver.Chrome(service=service, options=options)

# Buka halaman dengan formulir checkbox
url = "http://the-internet.herokuapp.com/checkboxes"
driver.get(url)
time.sleep(3)

# Cari elemen-elemen checkbox menggunakan XPath
checkbox1 = driver.find_element(By.XPATH, "//input[@type='checkbox'][1]")
checkbox2 = driver.find_element(By.XPATH, "//input[@type='checkbox'][2]")

# Klik checkbox pertama
checkbox1.click()
time.sleep(1)
checkbox1.click()
time.sleep(1)

# Klik checkbox kedua
checkbox2.click()
time.sleep(1)
checkbox2.click()
time.sleep(1)

# Tutup browser saat selesai
driver.quit()


import sqlalchemy as sa
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session

from app import models
from app.filters import SaintFilter
from app.models import Saint
from app.schemas import SaintCreate, SaintUpdate
from ..base import CRUDBase

class CRUDSaint(CRUDBase[Saint, SaintCreate, SaintUpdate, SaintFilter]):

    def get_multi_by_filter(self, db: Session, *, filter: SaintFilter) -> sa.Select:
        select: sa.Select = sa.select(self.model).outerjoin(models.Dignity).outerjoin(models.FaceSanctity)
        select: sa.Select = self._filter_and_sort_select(select, filter=filter)
        return select

    def create_with_any(
            self,
            db: Session,
            *,
            obj_in: SaintCreate,
            dignity_id: int | None = None,
            face_sanctity_id: int | None = None,
    ) -> Saint:
        obj_in_data = jsonable_encoder(obj_in)
        db_obj = self.model(
            **obj_in_data,
            dignity_id=dignity_id,
            face_sanctity_id=face_sanctity_id,
        )
        db.add(db_obj)
        db.commit()
        db.refresh(db_obj)
        return db_obj

    def get_or_create_saint(self, db: Session, *, obj_in: SaintCreate) -> Saint:
        db_obj = self.get_by_slug(db, slug=obj_in.slug)
        if not db_obj:
            db_obj = self.create(db, obj_in=obj_in)
        return db_obj

saint = CRUDSaint(Saint)


import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

cantidad_gente = 50

n = cantidad_gente - 1
p = 1 / (cantidad_gente - 1)
dinero_inicio = 50

banco = dinero_inicio*np.ones([cantidad_gente])

range = np.arange(cantidad_gente)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

bar = plt.bar(range,banco)

def init():
    return bar

def animate(i):
    global banco, ax
    gente_sdinero = sum(banco==0)
    muestra_sdinero = np.random.binomial(cantidad_gente - 1 - gente_sdinero, p, cantidad_gente)
    muestra_codinero = np.random.binomial(cantidad_gente - gente_sdinero, p, cantidad_gente)
    muestra_sdinero[banco == 0] = 0
    muestra_codinero[banco > 0] = 0
    sample = muestra_sdinero + muestra_codinero
    banco = banco + sample - 1*(banco > 0)
    banco = np.sort(banco)
    for rect, y in zip(bar, banco):
        rect.set_height(y)
    ax.set_ylim(0,max(banco))
    ax.set_title(i)
    #print(sum(banco)/cantidad_gente)
    return bar

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=3000, interval=1, blit=False)

anim.save('animacion.mp4', fps=60, extra_args=['-vcodec', 'libx264'])

plt.show()


import Chemins
from Utils import UTILS_Adaptations
from Utils.UTILS_Traduction import _
import wx
import GestionDB
from Utils import UTILS_Interface
from Ctrl.CTRL_ObjectListView import FastObjectListView, ColumnDefn, Filter, CTRL_Outils
from Ctrl.CTRL_Tarification_calcul import LISTE_METHODES
from Utils import UTILS_Texte
from Dlg.DLG_Ouvertures import Track_tarif

class ListView(FastObjectListView):
    def __init__(self, *args, **kwds):
        # Récupération des paramètres perso
        self.track_evenement = kwds.pop("track_evenement", None)
        self.dictCategories = self.GetCategoriesTarifs()
        self.donnees = self.track_evenement.tarifs
        # Initialisation du listCtrl
        self.nom_fichier_liste = __file__
        FastObjectListView.__init__(self, *args, **kwds)
        # Binds perso
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
        self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)

    def OnItemActivated(self,event):
        self.Modifier(None)

    def InitModel(self):
        pass
        #self.donnees = self.GetTracks()

    def GetCategoriesTarifs(self):
        DB = GestionDB.DB()
        req = """SELECT IDcategorie_tarif, nom
        FROM categories_tarifs
        WHERE IDactivite=%d;""" % self.track_evenement.IDactivite
        DB.ExecuterReq(req)
        listeCategories = DB.ResultatReq()
        dictCategories = {}
        for IDcategorie_tarif, nom in listeCategories:
            dictCategories[IDcategorie_tarif] = nom
        DB.Close()
        return dictCategories

    def GetTracks(self):
        """ Récupération des données """
        return self.track_evenement.tarifs

        # listeID = None
        # DB = GestionDB.DB()
        # req = """SELECT IDtarif, methode, categories_tarifs, description
        # FROM tarifs
        # WHERE IDevenement=%d
        # ;""" % self.IDevenement
        # DB.ExecuterReq(req)
        # listeDonnees = DB.ResultatReq()
        # DB.Close()
        # listeListeView = []
        # for item in listeDonnees :
        #     valide = True
        #     if listeID != None :
        #         if item[0] not in listeID :
        #             valide = False
        #     if valide == True :
        #         track = Track(item)
        #         listeListeView.append(track)
        #         if self.selectionID == item[0] :
        #             self.selectionTrack = track
        # return listeListeView

    def InitObjectListView(self):
        # Couleur en alternance des lignes
        self.oddRowsBackColor = UTILS_Interface.GetValeur("couleur_tres_claire", wx.Colour(240, 251, 237))
        self.evenRowsBackColor = wx.Colour(255, 255, 255)
        self.useExpansionColumn = True

        def GetMethode(code):
            for dictValeurs in LISTE_METHODES:
                if dictValeurs["code"] == code :
                    return dictValeurs["label"]
            return ""

        def GetCategories(categories_tarifs):
            listeTemp = []
            for IDcategorie in UTILS_Texte.ConvertStrToListe(categories_tarifs) :
                if IDcategorie in self.dictCategories :
                    listeTemp.append(self.dictCategories[IDcategorie])
            return ", ".join(listeTemp)

        liste_Colonnes = [
            ColumnDefn(u"", "left", 0, "IDtarif", typeDonnee="entier"),
            ColumnDefn(_(u"Description"), "left", 140, "description", typeDonnee="texte"),
            ColumnDefn(_(u"Méthode de calcul"), 'left', 140, "methode", typeDonnee="texte", stringConverter=GetMethode),
            ColumnDefn(_(u"Catégories de tarifs"), "left", 140, "categories_tarifs", typeDonnee="texte", stringConverter=GetCategories),
            ]

        self.SetColumns(liste_Colonnes)
        self.SetEmptyListMsg(_(u"Aucun tarif"))
        self.SetEmptyListMsgFont(wx.FFont(11, wx.DEFAULT, False, "Tekton"))
        self.SetSortColumn(self.columns[1])
        self.SetObjects(self.donnees)

    def MAJ(self, track=None):
        self.InitModel()
        self.InitObjectListView()
        # Sélection d'un item
        if track != None :
            self.SelectObject(track, deselectOthers=True, ensureVisible=True)

    def Selection(self):
        return self.GetSelectedObjects()

    def OnContextMenu(self, event):
        """Ouverture du menu contextuel """
        if len(self.Selection()) == 0:
            noSelection = True
        else:
            noSelection = False

        # Création du menu contextuel
        menuPop = UTILS_Adaptations.Menu()

        # Item Modifier
        item = wx.MenuItem(menuPop, 10, _(u"Ajouter"))
        bmp = wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Ajouter.png"), wx.BITMAP_TYPE_PNG)
        item.SetBitmap(bmp)
        menuPop.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.Ajouter, id=10)

        # Item Ajouter
        item = wx.MenuItem(menuPop, 20, _(u"Modifier"))
        bmp = wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Modifier.png"), wx.BITMAP_TYPE_PNG)
        item.SetBitmap(bmp)
        menuPop.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.Modifier, id=20)
        if noSelection == True : item.Enable(False)

        # Item Supprimer
        item = wx.MenuItem(menuPop, 30, _(u"Supprimer"))
        bmp = wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Supprimer.png"), wx.BITMAP_TYPE_PNG)
        item.SetBitmap(bmp)
        menuPop.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.Supprimer, id=30)
        if noSelection == True : item.Enable(False)

        self.PopupMenu(menuPop)
        menuPop.Destroy()

    def Ajouter(self, event):
        track_tarif = Track_tarif(dictDonnees={"IDactivite":self.track_evenement.IDactivite, "date_debut":self.track_evenement.date, "date_fin":self.track_evenement.date})
        nom_evenement = self.GetParent().ctrl_nom.GetValue()
        from Dlg import DLG_Saisie_tarification
        dlg = DLG_Saisie_tarification.Dialog(self, IDactivite=self.track_evenement.IDactivite, IDtarif=None, nom_tarif=nom_evenement,
                                             choix_pages=["generalites", "conditions", "calcul"], cacher_dates=True, track_tarif=track_tarif)
        dlg.toolbook.GetPage("calcul").SetFiltreTypeTarif("JOURN")
        if dlg.ShowModal() == wx.ID_OK:
            track_tarif = dlg.GetTrackTarif()
            self.donnees.append(track_tarif)
            self.MAJ(track_tarif)
        dlg.Destroy()

    def Modifier(self, event):
        if len(self.Selection()) == 0 :
            dlg = wx.MessageDialog(self, _(u"Vous n'avez sélectionné aucun tarif à modifier dans la liste !"), _(u"Erreur de saisie"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            return
        track_tarif = self.Selection()[0]
        nom_evenement = self.GetParent().ctrl_nom.GetValue()
        from Dlg import DLG_Saisie_tarification
        dlg = DLG_Saisie_tarification.Dialog(self, IDactivite=self.track_evenement.IDactivite, IDtarif=None, nom_tarif=nom_evenement, choix_pages=["generalites", "conditions", "calcul"], cacher_dates=True, track_tarif=track_tarif)
        dlg.toolbook.GetPage("calcul").SetFiltreTypeTarif("JOURN")
        if dlg.ShowModal() == wx.ID_OK:
            track_tarif.dirty = True
            self.MAJ(track_tarif)
        dlg.Destroy()

    def Supprimer(self, event):
        if len(self.Selection()) == 0 :
            dlg = wx.MessageDialog(self, _(u"Vous n'avez sélectionné aucun tarif à supprimer dans la liste !"), _(u"Erreur de saisie"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            return
        track_tarif = self.Selection()[0]

        # Vérifie que ce tarif n'est pas déjà attribué à une prestation
        if track_tarif.IDtarif != None :
            DB = GestionDB.DB()
            req = """SELECT IDprestation FROM prestations WHERE IDtarif=%d;""" % track_tarif.IDtarif
            DB.ExecuterReq(req)
            listePrestations = DB.ResultatReq()
            DB.Close()
            nbrePrestations = len(listePrestations)
            if nbrePrestations > 0 :
                dlg = wx.MessageDialog(self, _(u"Ce tarif a déjà été attribué à %d prestations.\nIl est donc impossible de le supprimer !") % nbrePrestations, _(u"Suppression impossible"), wx.OK | wx.ICON_EXCLAMATION)
                dlg.ShowModal()
                dlg.Destroy()
                return

        dlg = wx.MessageDialog(self, _(u"Souhaitez-vous vraiment supprimer ce tarif ?"), _(u"Suppression"), wx.YES_NO|wx.NO_DEFAULT|wx.CANCEL|wx.ICON_INFORMATION)
        if dlg.ShowModal() == wx.ID_YES :
            # DB = GestionDB.DB()
            # DB.ReqDEL("tarifs", "IDtarif", IDtarif)
            # DB.ReqDEL("combi_tarifs", "IDtarif", IDtarif)
            # DB.ReqDEL("combi_tarifs_unites", "IDtarif", IDtarif)
            # DB.ReqDEL("tarifs_lignes", "IDtarif", IDtarif)
            # DB.Close()
            self.donnees.remove(track_tarif)
            self.MAJ()
        dlg.Destroy()

    def GetTracksTarifs(self):
        return self.donnees

# -------------------------------------------------------------------------------------------------------------------------------------------

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        panel = wx.Panel(self, -1, name="test1")
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(panel, 1, wx.ALL|wx.EXPAND)
        self.SetSizer(sizer_1)
        self.myOlv = ListView(panel, id=-1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES)
        self.myOlv.MAJ()
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        sizer_2.Add(self.myOlv, 1, wx.ALL|wx.EXPAND, 4)
        panel.SetSizer(sizer_2)
        self.Layout()

if __name__ == '__main__':
    app = wx.App(0)
    #wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "OL TEST")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()


# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import AccessError

import requests
import json

class Company(models.Model):
    _name = 'res.company'
    _inherit = 'res.company'

    client_id = fields.Char(string="Planet ID")
    client_secret = fields.Char(string="Planet secret")

    def connection_pos(self):
        company_field = self.env['res.company'].search([], limit=1)
        client_id = company_field.client_id
        secret = company_field.client_secret
        url = 'https://auth.tax.planetpayment.ae/auth/realms/planet/protocol/openid-connect/token'
        # url = 'https://auth.qa-tax.planetpayment.ae/auth/realms/planet/protocol/openid-connect/token'
        payload = {'client_id': '%s' % client_id, 'client_secret': '%s' % secret, 'grant_type': 'client_credentials'}

        try:
            request = requests.post(url, data=payload)

            token = request.json()
            return token
        except:
            raise AccessError(_("No connection.Please contact the manager to confirm contact information..."))


import sys
import codecs
import random
import json

all_sents=codecs.open(sys.argv[1],'r','utf8').readlines()

setnr=10
myList=[i for i in range(250)]

for i in range(setnr):
	index_dict={'train':[],'test':[],'dev':[]}
	test_f= codecs.open('set'+str(i)+'/test','w','utf8')
	dev_f= codecs.open('set'+str(i)+'/dev','w','utf8')
	train_f= codecs.open('set'+str(i)+'/train','w','utf8')
	random.shuffle(myList)
	for lnr in myList[:100]:
		index_dict['train']=myList[:100]
		train_f.write(all_sents[lnr])
	for lnr in myList[100:200]:
		index_dict['dev']=myList[100:200]
		dev_f.write(all_sents[lnr])
	for lnr in myList[200:]:
		index_dict['test']=myList[200:]
		test_f.write(all_sents[lnr])
	jsfile = open('set'+str(i)+'/indices.json', 'w')
	json.dump(index_dict,jsfile)
	jsfile.close()
	test_f.close()
	train_f.close()
	dev_f.close()


#!/usr/bin/env python3

import argparse
import subprocess
import sys

def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('command')
    parser.add_argument('expected')
    args = parser.parse_args()

    out = subprocess.run(args.command, stdout=subprocess.PIPE)
    actual = out.stdout.decode().strip()

    if args.expected != actual:
        print('expected:', args.expected, file=sys.stderr)
        print('actual:  ', actual, file=sys.stderr)
        sys.exit(1)
    sys.exit(0)

if __name__ == "__main__":
    main()

test cases/rust/16 internal c dependencies/test.py


import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel

class ContentTagRecommender:
    def __init__(self,
    movies : pd.DataFrame, tags : pd.DataFrame):
        self.prepare(movies,tags)

    def prepare(self, movies : pd.DataFrame, tags : pd.DataFrame):
        self.tags = tags

        self.movie_metadata = pd.merge(movies,tags, how='inner')
        self.movie_metadata = self.movie_metadata.groupby(['title','genres'])['tag'].apply(','.join).reset_index()
        self.movie_metadata['genres'] = self.movie_metadata['genres'].str.replace("|", ",")
        self.movie_mapping = pd.Series(self.movie_metadata.index,index = self.movie_metadata['title']).drop_duplicates()

        tfidf = TfidfVectorizer(stop_words='english')

        overview_matrix = tfidf.fit_transform(self.movie_metadata['tag'])
        overview_matrix_genres = tfidf.fit_transform(self.movie_metadata['genres'])
        self.similarity_matrix = linear_kernel(overview_matrix,overview_matrix)
        self.genres_similarity_matrix = linear_kernel(overview_matrix_genres,overview_matrix_genres)

    def recommend(self,targetTitle : str, limit : int):
        similarity_tag_score = self.getTagSimilarityScore(targetTitle)
        similarity_genre_score = self.getGenreSimilarityScore(targetTitle)

        # prevent the given movie from being recommended
        movie_data = self.movie_metadata[self.movie_metadata['title'] != targetTitle]
        movie_data['idx'] = movie_data.index

        sim_score_tag = pd.DataFrame(similarity_tag_score)
        sim_score_tag = sim_score_tag.rename(columns={0:'idx',1:'sim_score_tag'})

        sim_score_genre = pd.DataFrame(similarity_genre_score)
        sim_score_genre = sim_score_genre.rename(columns={0:'idx',1:'sim_score_genre'})

        movie_data = pd.merge(movie_data,sim_score_tag, how='inner', left_on=movie_data.index,right_on=['idx'])
        movie_data = pd.merge(movie_data,sim_score_genre, how='inner', left_on=movie_data.index,right_on=['idx'])
        movie_data = movie_data[['title','tag','genres','sim_score_genre','sim_score_tag']]
        movie_data['tot_score'] = movie_data['sim_score_genre'] + (movie_data['sim_score_tag'] * 2 ) / 3
        return movie_data.sort_values(['tot_score'], ascending=False)[:limit]

    def getTagSimilarityScore(self, targetTitle : str):
        movie_idx = self.movie_mapping[targetTitle]
        return sorted(list(enumerate(self.similarity_matrix[movie_idx])), key=lambda x: x[1], reverse=True)

    def getGenreSimilarityScore(self,targetTitle : str):
        movie_idx = self.movie_mapping[targetTitle]
        return sorted(list(enumerate(self.genres_similarity_matrix[movie_idx])), key=lambda x: x[1], reverse=True)


'''
This script performs a time-series cross-validation of multiple training-test
splits on a loaded supervised learning dataset with applied feature scaling.

Note: The 'perform_timeseries_CV' function is hard coded to only perform
      cross-validation on either: multilinear regression, support vector
      regression, multi-layer perceptron, or long short-term memory model.

This script does the following:
    1. Load supervised learning dataset (either stationary or non-stationary)
    2. Apply feature scaling
    3. Perform cross-validation over 9 training-test splits
'''
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
from keras.models import Sequential
from keras.layers import Dense, LSTM

def load_dataset(file_name):
    '''
    Function:
        Read data from .csv file into returned Pandas DataFrame of Series.
    Arguments:
        file_name: Name of .csv file
    Returns:
        Pandas DataFrame of series.
    '''
    return pd.read_csv(file_name)

def write_dataset(data, file_name):
    '''
    Function:
        Write data from Pandas DataFrame into .csv file of specified file name.
    Arguments:
        data: Sequence of observations as a Pandas DataFrame of Series.
        file_name: String text of .csv file name.
    '''
    data.to_csv(file_name, index=False, sep=',')

def display_graph(data, features_of_interest):
    '''
    Function:
        Display multiple line plots of separate feature variables against time
    Arguments:
        data: Sequence of observations as a Pandas DataFrame of Series.
        features_of_interest: Specified features columns in dataset
    '''
    i = 1
    plt.figure()
    for feature in features_of_interest:
        plt.subplot(len(features_of_interest), 1, i)
        plt.plot(data.iloc[:, feature])
        plt.title(data.columns[feature], y=0.5, loc='right')
        i += 1
    plt.show()

def create_mlr_model(train_X, train_y):
    '''
    Function:
        Create multi-linear regression (MLR) model and fit to training set.
    Arguments:
        train_X: Training set's feature matrix as Pandas Dataframe.
        train_y: Training set's output vector as Pandas Dataframe.
    Returns:
        sklearn LinearRegression object fitted to the training set.
    '''
    # Design MLR model
    model = LinearRegression()

    # Fit MLR model
    model.fit(train_X, train_y)
    return model

def create_svr_model(train_X, train_y):
    '''
    Function:
        Creates support vector regression (SVR) model and fit to training set.
    Arguments:
        train_X: Training set's feature matrix as Pandas Dataframe.
        train_y: Training set's output vector as Pandas Dataframe.
    Returns:
        sklearn SVR object fitted to the training set.
    '''
    # Design SVR model
    model = SVR(kernel='rbf')

    # Fit SVR model
    model.fit(train_X, train_y)
    return model

def create_mlp_model(train_X, train_y, n_epoch, n_batch):
    '''
    Function:
        Creates multi-layer perceptron (MLP) model and fit to training set.
    Arguments:
        train_X: Training set's feature matrix as Pandas Dataframe.
        train_y: Training set's output vector as Pandas Dataframe.
        n_epoch: Number of training epochs.
        n_batch: Number of mini batch size.
    Returns:
        keras Sequential object fitted to the training set.
    '''
    # Design MLP network
    model = Sequential()
    model.add(Dense(units=50, input_dim=50, kernel_initializer='normal', activation='relu'))
    model.add(Dense(units=50, kernel_initializer='normal', activation='relu'))
    model.add(Dense(units=1, kernel_initializer='normal'))
    model.compile(loss='mean_squared_error', optimizer='adam')

    # Fit MLP network
    history = model.fit(train_X, train_y, batch_size=n_batch, epochs=n_epoch, shuffle=False)
    return model, history

def create_lstm_model(train_X, valid_X, train_y, valid_y, n_neuron, n_epoch, n_batch):
    '''
    Function:
        Creates long short-term memory (LSTM) model and fit to training set.
    Arguments:
        train_X: Training set's feature matrix as Pandas Dataframe.
        train_y: Training set's output vector as Pandas Dataframe.
        valid_X: Validation set's feature matrix as Pandas Dataframe.
        valid_y: Validation set's output vector as Pandas Dataframe.
        n_neuron: Number of memory units.
        n_epoch: Number of training epochs.
        n_batch: Number of mini batch size.
    Returns:
        keras Sequential object fitted to the training set.
    '''
    # Reshape feature input into 3D [samples, timesteps, features]
    train_X = train_X.reshape((train_X.shape[0], 1, train_X.shape[1]))
    valid_X = valid_X.reshape((valid_X.shape[0], 1, valid_X.shape[1]))

    # Design LSTM network
    model = Sequential()
    model.add(LSTM(n_neuron, input_shape=(train_X.shape[1], train_X.shape[2])))
    model.add(Dense(1))
    model.compile(loss='mean_squared_error', optimizer='adam')

    # Fit network
    history = model.fit(train_X, train_y, epochs=n_epoch, batch_size=n_batch, validation_data=(valid_X, valid_y), verbose=2, shuffle=False)
    return model,history

def split_dataset(dataset, n_year):
    '''
    Function:
        Split the dataset into its training and validation sets as well as
        its feature matrix (X) and output vector (y). The split is made at
        the defined number of years beyond the beginning of the dataset.

    Arguments:
        dataset: Sequence of observations as a Pandas DataFrame of Series.
        n_year: Number of years from the beginning of the dataset.
    Returns:
        Pandas DataFrames of series of the feature matrix (X) and output
        vector (y) from its training and validation set, respectively.

    Note:
        This function is hard coded for multiple training-test splits for
        cross-validation.
    '''
    # Split dataset into training and test set
    split = 365 * 24 * n_year
    train = dataset[:split, :]
    valid = dataset[split:split+8760, :]

    # Split each set into feature matrix (X) and output vector (y)
    train_X, train_y = train[:, :-1], train[:, -1]
    valid_X, valid_y = valid[:, :-1], valid[:, -1]

    return train_X, train_y, valid_X, valid_y

def performance_test(dataset, model, scaler, input_dim, n_fold):
    '''
    Function:
        Compute the predicted output vector using the 'predict' method by
        the 'model' object. Inverse transformation is applied to revert
        both predicted and observed output vectors back to its original scale.
    Arguments:
        dataset: Sequence of observations as a Pandas DataFrame of Series.
        model: Object created via 'create_model' function.
        scaler: sklearn object associated with feature scaling.
        input_dim: Input dimensions that the model object is compatible with where
            'input_dim=2' represent 2D and 'input_dim=3' represent 3D. Any other
            value will cause the function to return None values.
    Returns:
        Pandas DataFrame of the predicted and observed output vectors respectively
    '''
    # Split dataset
    train_X, train_y, test_X, test_y = split_dataset(dataset, n_fold)

    # Compute predicted outputs
    if input_dim == 2:
        y_predict = model.predict(test_X)
        y_predict = y_predict.reshape((len(y_predict),1))
    elif input_dim == 3:
        y_predict = model.predict(test_X.reshape((test_X.shape[0], 1, test_X.shape[1])))
    else:
        print("Invalid Dimensions for model prediction")
        inv_y_predict, inv_y = None, None
        return inv_y_predict, inv_y

    # Invert scaling for predicted output
    inv_y_predict = np.concatenate((test_X, y_predict), axis=1)
    inv_y_predict = scaler.inverse_transform(inv_y_predict)
    inv_y_predict = inv_y_predict[:,-1]

    # Invert scaling for observed output
    inv_y = np.concatenate((test_X, test_y.reshape((len(test_y),1))), axis=1)
    inv_y = scaler.inverse_transform(inv_y)
    inv_y = inv_y[:,-1]

    return inv_y_predict, inv_y

def performance_evaluate(dataset, y_pred, y):
    '''
    Function:
        Compute performance metrics that includes:
            - mean square error
            - root mean square error
            - mean absolute error
            - mean bias error
            - R-squared
            - adjusted R-squared
    Arguments:
        dataset: Sequence of observations as a Pandas DataFrame of Series.
        y_pred: Predicted output vector as a Pandas DataFrame of Series.
        y: Observed output vector as a Pandas DataFrame of Series.
    Returns:
        List of performance metric values
    '''
    # Performance Metrics
    mbe = sum(y-y_pred)/len(y)
    mse = np.sqrt(mean_squared_error(y, y_pred))
    rmse = np.sqrt(mse)
    mae = mean_absolute_error(y, y_pred)
    r2 = r2_score(y, y_pred)
    adj_r2 = r2*((dataset.shape[0]-1)/(dataset.shape[0]-(dataset.shape[1]-1)-1))

    return [mse, rmse, mae, mbe, r2, adj_r2]

def perform_timeseries_CV(dataset, n_folds, algorithm, scaler, n_epoch=50, n_batch=72):
    '''
    Function:
        Perform time series cross validation on the specified learning algorithm and
        evaluate the performance metrics over multiple training-test splits.
    Arguments:
        dataset: Sequence of observations as a Pandas DataFrame of Series.
        n_folds: Number of iterations
        algorithm: String text of learning model's abbreviation.
        scaler: sklearn object associated with feature scaling.
        n_epoch: Number of training epochs
        n_batch: Number of mini batch size
    Returns:
        Pandas DataFrame of series containing performance metrics.
    '''
    result_array = []
    for n in range(1, n_folds):
        # Perform training-test according to current n-fold
        print("K-Fold: ", n)
        train_X, train_y, valid_X, valid_y = split_dataset(dataset, n)

        # Train model based on passed 'algorithm' argument
        if algorithm == 'LSTM':
            print("Training LSTM model...")
            model, history = create_lstm_model(train_X, valid_X, train_y, valid_y, n_neuron=100, n_epoch=n_epoch, n_batch=n_batch)
            inv_yhat, inv_y = performance_test(dataset, model, scaler, 3, n)
            plt.plot(history.history['loss'], label='train', color='blue')
            plt.plot(history.history['val_loss'], label='test', color='orange')
        elif algorithm == 'MLP':
            print("Training MLP model...")
            model, history = create_mlp_model(train_X, train_y, n_epoch=n_epoch, n_batch=n_batch)
            inv_yhat, inv_y = performance_test(dataset, model, scaler, 2, n)
            plt.plot(history.history['loss'], label='train')
        elif algorithm == 'SVR':
            print("Training SVR model...")
            model = create_svr_model(train_X, train_y)
            inv_yhat, inv_y = performance_test(dataset, model, scaler, 2, n)
        elif algorithm == 'MLR':
            print("Training MLR model...")
            model = create_mlr_model(train_X, train_y)
            inv_yhat, inv_y = performance_test(dataset, model, scaler, 2, n)
        else:
            print("No Algorithms Found...")
            print("K-Fold Cross Validation ended")
            break
        print("Training model complete!")

        # Compute performance metrics and store into array
        result = performance_evaluate(dataset, inv_yhat, inv_y)
        result.insert(0, n)
        result_array.append(result)

    # Format and print mean performance metric results
    result_array = pd.DataFrame(result_array)
    result_array.columns = ['k-Fold', 'MSE', 'RMSE', 'MAE', 'MBE', 'R2', 'adj R2']

    print("Mean MSE: %.3f" % result_array['MSE'].mean())
    print("Mean RMSE: %.3f" % result_array['RMSE'].mean())
    print("Mean MAE: %.3f" % result_array['MAE'].mean())
    print("Mean MBE: %.3f" % result_array['MBE'].mean())
    print("Mean r2: %.3f" % result_array['R2'].mean())
    print("Mean adj r2: %.3f" % result_array['adj R2'].mean())

    print("K-Fold Cross Validation has been completed!")
    plt.show()
    return result_array

def persistence_model(data):
    '''
    Function:
        Assuming the dataset is transformed for supervised learning, return
        the predicted and observed output vectors.
    Arguments:
        data: Sequence of observations as a Pandas DataFrame of Series.
    Returns:
        Pandas DataFrame of the predicted and observed output vectors respectively
    '''
    y_actual = data.iloc[:,-1]
    y_predict = data.iloc[:,-2]
    return y_actual, y_predict

def persistence_forecast(data):
    '''
    Function:
        Perform persistence forecast and return its performance metric values.
    Arguments:
        data: Sequence of observations as a Pandas DataFrame of Series.
    Returns:
        List of performance metric values
    '''
    y_actual, y_predict = persistence_model(data)
    return performance_evaluate(data, y_predict, y_actual)

# 1. Load supervised learning dataset (either stationary or non-stationary)
dataset = load_dataset("Case 5.1 - stationary.csv")
dataset = load_dataset("Case 5.2 - non stationary.csv")

# (Optional) Dataset Visualization
col_of_interest = [n for n in range(0, len(dataset.columns))]
display_graph(dataset, col_of_interest)

# 2. Apply feature scaling
scaler = MinMaxScaler(feature_range=(-1, 1))
dataset = scaler.fit_transform(dataset)

# 3. Perform cross-validation over 9 training-test splits
result_mlr = perform_timeseries_CV(dataset, 9, 'MLR', scaler)
result_svr = perform_timeseries_CV(dataset, 9, 'SVR', scaler)
result_mlp = perform_timeseries_CV(dataset, 9, 'MLP', scaler)
result_lstm = perform_timeseries_CV(dataset, 9, 'LSTM', scaler)


import os, sys
import urllib2
import json

def main(szUserName):
    # Assemble the GitHub URL to query
    github_url = "https://api.github.com/users/" + szUserName + "/repos"
    print("[INFO] Looking for repositories from @%s" % szUserName)
    response = urllib2.urlopen(github_url)
    json_obj = response.read()
    data = json.loads(json_obj)
    for item in data:
        print("       [+] https://github.com/%s" % item['full_name'])
    response.close()

if __name__ == "__main__":
    if (len(sys.argv) < 2):
        print("[+] Usage: %s [Github_UserName]" % sys.argv[0])
        sys.exit(0)
    else:
        szUserName = sys.argv[1]
        main(szUserName)


from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPainter, QPen, QBrush
from PyQt5.QtCore import Qt
import sys
from random import randint as r
from qq import Ui_MainWindow

class Main(Ui_MainWindow, QMainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.flag = False

        self.pushButton.clicked.connect(self.run)

    def run(self):
        self.flag = True
        self.update()

    def paintEvent(self, event):
        if self.flag is True:
            x = r(0, 500)
            y = r(0, 600)
            l = r(0, 500)
            painter = QPainter(self)
            a = r(1, 5)
            if a == 1:
                painter.setPen(QPen(Qt.yellow, 5, Qt.SolidLine))
                painter.setBrush(QBrush(Qt.yellow, Qt.SolidPattern))
            if a == 2:
                painter.setPen(QPen(Qt.red, 5, Qt.SolidLine))
                painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
            if a == 3:
                painter.setPen(QPen(Qt.blue, 5, Qt.SolidLine))
                painter.setBrush(QBrush(Qt.blue, Qt.SolidPattern))
            if a == 4:
                painter.setPen(QPen(Qt.purple, 5, Qt.SolidLine))
                painter.setBrush(QBrush(Qt.purple, Qt.SolidPattern))
            if a == 5:
                painter.setPen(QPen(Qt.green, 5, Qt.SolidLine))
                painter.setBrush(QBrush(Qt.green, Qt.SolidPattern))
            painter.drawEllipse(x, y, l, l)
            self.flag = False

app = QApplication(sys.argv)
ex = Main()
ex.show()
sys.exit(app.exec_())