import FWCore.ParameterSet.Config as cms

process = cms.Process( "ElectronIsolation" )
process.maxEvents = cms.untracked.PSet(
    input = cms.untracked.int32(10000)
)

process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff')
process.load("Configuration.StandardSequences.GeometryRecoDB_cff")
process.GlobalTag.globaltag = '76X_mcRun2_asymptotic_RunIIFall15DR76_v1'
process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
process.options.allowUnscheduled = cms.untracked.bool(False)

process.load("EgammaWork.ElectronNtupler.pfNoLeptons_cfi")
process.pfNoLeptons.src = cms.InputTag('particleFlow')
process.load("CommonTools.ParticleFlow.pfNoPileUpIso_cff")
process.load("CommonTools.ParticleFlow.pfParticleSelection_cff")

process.pfNoPileUpCandidates = process.pfAllChargedHadrons.clone()
process.pfNoPileUpCandidates.pdgId.extend(process.pfAllNeutralHadronsAndPhotons.pdgId)

process.load("CommonTools.PileupAlgos.Puppi_cff")
process.puppi.candName = cms.InputTag('particleFlow')
process.puppi.vertexName = cms.InputTag('offlinePrimaryVertices')
process.puppi.puppiForLeptons = False

process.puppiNoLeptons = process.puppi.clone()
process.puppiNoLeptons.puppiForLeptons = False
process.puppiNoLeptons.candName = cms.InputTag('pfNoLeptons')

useAOD = True
#
# Set up electron ID (VID framework)
#

from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
# turn on VID producer, indicate data format  to be
# DataFormat.AOD or DataFormat.MiniAOD, as appropriate
if useAOD == True :
    dataFormat = DataFormat.AOD
else :
    dataFormat = DataFormat.MiniAOD

switchOnVIDElectronIdProducer(process, dataFormat)

# define which IDs we want to produce
my_id_modules = ['RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff']

#add them to the VID producer
for idmod in my_id_modules:
    setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)

#standard isolation with cone veto
process.ElectronIsolationConeVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('pfNoPileUpCandidates'),
					   	isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.015),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.0),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.08),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

#standard isolation with map based veto
process.ElectronIsolationMapBasedVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('pfNoPileUpCandidates'),
					   	isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

#puppi isolation with cone veto
process.ElectronIsolationOnPUPPIConeVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('puppi'),
					    isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.015),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.0),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.08),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

#puppi no leptons with cone veto
process.ElectronIsolationOnPUPPINoLeptonsConeVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('puppiNoLeptons'),
					    isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.015),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.0),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithConeVeto'),
									coneSize = cms.double(0.3),
									VetoConeSizeEndcaps = cms.double(0.08),
									VetoConeSizeBarrel = cms.double(0.0),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

#puppi isolation with map based veto
process.ElectronIsolationOnPUPPIMapBasedVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('puppi'),
					    isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

#puppi no leptons with map based veto
process.ElectronIsolationOnPUPPINoLeptonsMapBasedVeto = cms.EDProducer("CITKPFIsolationSumProducer",
					    srcToIsolate = cms.InputTag("gedGsfElectrons"),
					    srcForIsolationCone = cms.InputTag('puppiNoLeptons'),
					    isolationConeDefinitions = cms.VPSet(
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h+'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('h0'),
									miniAODVertexCodes = cms.vuint32(2,3) ),
									cms.PSet( isolationAlgo = cms.string('ElectronPFIsolationWithMapBasedVeto'),
									coneSize = cms.double(0.3),
									isolateAgainst = cms.string('gamma'),
									miniAODVertexCodes = cms.vuint32(2,3) )
								      )
					)

process.ntupler = cms.EDAnalyzer('ElectronNtupler',
				 pruned = cms.InputTag("genParticles"),
				 pileup = cms.InputTag("addPileupInfo"),
				 vertices = cms.InputTag("offlinePrimaryVertices"),
				 electrons = cms.InputTag("gedGsfElectrons"),
				 cand_src = cms.InputTag("particleFlow"),
				 rho = cms.InputTag("fixedGridRhoFastjetAll"),
				 #CITK
				 ValueMaps_ChargedHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationConeVeto", "h+-DR030-BarVeto000-EndVeto001"),
				 ValueMaps_NeutralHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationConeVeto", "h0-DR030-BarVeto000-EndVeto000"),
				 ValueMaps_Photons_ConeVeto_src = cms.InputTag("ElectronIsolationConeVeto", "gamma-DR030-BarVeto000-EndVeto008"),

				 ValueMaps_ChargedHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationMapBasedVeto", "h+-DR030-"),
				 ValueMaps_NeutralHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationMapBasedVeto", "h0-DR030-"),
				 ValueMaps_Photons_MapBasedVeto_src = cms.InputTag("ElectronIsolationMapBasedVeto", "gamma-DR030-"),
				 #PUPPI
				 ValueMaps_PUPPI_ChargedHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPIConeVeto", "h+-DR030-BarVeto000-EndVeto001"),
				 ValueMaps_PUPPI_NeutralHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPIConeVeto", "h0-DR030-BarVeto000-EndVeto000"),
				 ValueMaps_PUPPI_Photons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPIConeVeto", "gamma-DR030-BarVeto000-EndVeto008"),

				  #PUPPI
				 ValueMaps_PUPPI_ChargedHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPIMapBasedVeto", "h+-DR030-"),
				 ValueMaps_PUPPI_NeutralHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPIMapBasedVeto", "h0-DR030-"),
				 ValueMaps_PUPPI_Photons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPIMapBasedVeto", "gamma-DR030-"),
				  #PUPPINoLeptons
				 ValueMaps_PUPPI_NoLeptons_ChargedHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsConeVeto", "h+-DR030-BarVeto000-EndVeto001"),
				 ValueMaps_PUPPI_NoLeptons_NeutralHadrons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsConeVeto", "h0-DR030-BarVeto000-EndVeto000"),
				 ValueMaps_PUPPI_NoLeptons_Photons_ConeVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsConeVeto", "gamma-DR030-BarVeto000-EndVeto008"),

				 ValueMaps_PUPPI_NoLeptons_ChargedHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsMapBasedVeto", "h+-DR030-"),
				 ValueMaps_PUPPI_NoLeptons_NeutralHadrons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsMapBasedVeto", "h0-DR030-"),
				 ValueMaps_PUPPI_NoLeptons_Photons_MapBasedVeto_src = cms.InputTag("ElectronIsolationOnPUPPINoLeptonsMapBasedVeto", "gamma-DR030-"),
				 # for electron ids
				 mva_idw80_src = cms.InputTag("egmGsfElectronIDs", "mvaEleID-Spring15-25ns-nonTrig-V1-wp80"),
				 mva_idw90_src = cms.InputTag("egmGsfElectronIDs", "mvaEleID-Spring15-25ns-nonTrig-V1-wp90"),
  				 #generator info
				 genInfo = cms.InputTag("generator"),
				 effAreaFile = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt"),
				)

process.particleFlowTmpPtrs = cms.EDProducer("PFCandidateFwdPtrProducer",
src = cms.InputTag('particleFlow')
)

process.electrons = cms.Path(process.particleFlowTmpPtrs + process.pfParticleSelectionSequence + process.pfNoPileUpCandidates + process.egmGsfElectronIDSequence + process.pfNoLeptons + process.puppi + process.puppiNoLeptons + process.ElectronIsolationConeVeto + process.ElectronIsolationMapBasedVeto + process.ElectronIsolationOnPUPPIConeVeto + process.ElectronIsolationOnPUPPINoLeptonsConeVeto + process.ElectronIsolationOnPUPPIMapBasedVeto + process.ElectronIsolationOnPUPPINoLeptonsMapBasedVeto + process.ntupler)

process.source = cms.Source("PoolSource",
       fileNames = cms.untracked.vstring('file:///afs/cern.ch/user/i/ishvetso/eos/cms/store/mc/RunIIFall15DR76/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/AODSIM/PU25nsData2015v1_76X_mcRun2_asymptotic_v12-v1/00000/5AAC31E2-1FC0-E511-994B-02163E00C3AD.root'),
)

process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 1000

process.TFileService = cms.Service("TFileService",
                                 fileName = cms.string("tree.root")
                                  )


from django.contrib import admin

from .models import Conversation

class ConversationAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['student', 'time', 'operator']}),
        ('评分', {'fields': ['deportment_score', 'deportment_problem',
                           'expression_score', 'expression_problem',
                           'resume_score', 'resume_problem',
                           'background_score', 'background_problem',
                           'project_score', 'project_problem',
                           'skill_point_score', 'skill_point_problem',
                           'mentality_score', 'mentality_problem',
                           ]}),
        ('总结', {'fields': ['task', 'task_completion']}),
    ]

    list_display = ('student', 'time')
    list_filter = ['time', 'student']
    # search_fields = ['student', 'time']

admin.site.register(Conversation, ConversationAdmin)


from itertools import combinations
from collections import Counter
def solution(orders, course):
    answer = []
    for i in course:
        course_size_list = []
        for j in orders:
            course_size_list.extend(list(combinations(sorted(j), i)))
        most_common = Counter(course_size_list).most_common()
        for i, v in most_common:
            if v >= 2 and v == most_common[0][1]:
                answer.append(''.join(list(i)))
    return sorted(answer)

orders = ["XYZ", "XWY", "WXA"]
course = [2, 3, 4]
# 	["ACD", "AD", "ADE", "CD", "XYZ"]

print(solution(orders, course))


# -*- coding: utf-8 -*-
from flask import Flask, request, render_template
from flask import Response, Request
import json
import logging
import appcfg
import meteo
import filterpy

__author__ = 'Dmitry Mittov <mittov@gmail.com>'

app = Flask(__name__)

HTTP_201_CREATED = 201

app.jinja_env.globals.update(format_temp=meteo.format_temp)
app.jinja_env.globals.update(format_humid=meteo.format_humid)

@app.route('/')
def main_page():
    current_readings = appcfg.MeteoState.current_readings(appcfg.SENSOR_ID)
    return render_template('graph.html',
                           current_readings=current_readings)

@app.route('/sensor/<name>', methods=['POST'])
def add_sensor_data(name):
    meteo.process_state(name, request.get_json())
    return "{'msg': 'ok'}", HTTP_201_CREATED

def transform_c3(meteo_states):
    temp = ['temp']
    temp += [float(state.temp) for state in meteo_states]
    humidity = ['humidity']
    humidity += [float(state.humidity) for state in meteo_states]
    return [temp, humidity]

@app.route('/day/<sensor>')
def get_last_day_data(sensor):
    meteo_states = appcfg.MeteoState.day_data(sensor)
    data = transform_c3(meteo_states)
    response = Response(response=json.dumps(data),
                        status=200,
                        mimetype="application/json")
    return response

if __name__ == '__main__':
    app.run(debug=True)


# Z-algorithmで解いてみる

N = int(input())
S = input()
ans = 0
for h in range(N):
    T = S[h:]
    M = len(T)
    Z = [0] * M
    c = 0
    for i in range(1, M):
        l = i - c  # 今見ている場所が計算済みcからどれだけ離れているか
        if i + Z[l] < c + Z[c]:
            Z[i] = Z[l]
        else:
            j = max(0, c + Z[c] - i)
            while i + j < M and T[j] == T[i + j]:
                j += 1
            Z[i] = j
            c = i
    # Z[0] = M
        # print(i, Z[i])
        if i >= Z[i]:
            ans = max(ans, Z[i])
print(ans)


import logging

import boto3
from box import Box
from crhelper import CfnResource
from schema import Optional

from codesmith.common import naming
from codesmith.common.calc import calculator, SSM_PARAMETER_DESCRIPTION
from codesmith.common.cfn import resource_properties
from codesmith.common.schema import non_empty_string, tolerant_schema
from codesmith.common.ssm import silent_delete_parameter_from_event, put_string_parameter

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

ssm = boto3.client('ssm')
expression_parser = calculator(1)

properties_schema = tolerant_schema({
    'SequenceName': non_empty_string,
    Optional('Expression'): non_empty_string
})

def validate_properties(properties):
    p = properties_schema.validate(properties)
    if 'expression' not in p:
        p['expression'] = 'x'
    expression_parser.parse(p['expression'])
    return Box(p, camel_killer_box=True)

@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
    return put_sequence_parameter(properties)

def put_sequence_parameter(properties):
    parameter_name = naming.sequence_parameter_name(properties.sequence_name)
    put_string_parameter(ssm, parameter_name,
                         value=properties.expression,
                         description=SSM_PARAMETER_DESCRIPTION)
    return parameter_name

@helper.delete
def delete(event, _):
    return silent_delete_parameter_from_event(ssm, event)

def handler(event, context):
    logger.info('event: %s', event)
    helper(event, context)


"""Unit tests for starlark helpers
See https://docs.bazel.build/versions/main/skylark/testing.html#for-testing-starlark-utilities
"""

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//python/private:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS")

required_platforms = [
    "x86_64-apple-darwin",
    "x86_64-unknown-linux-gnu",
]

def _smoke_test_impl(ctx):
    env = unittest.begin(ctx)
    for version in TOOL_VERSIONS.keys():
        platforms = TOOL_VERSIONS[version]
        for required_platform in required_platforms:
            asserts.true(
                env,
                required_platform in platforms.keys(),
                "Missing platform {} for version {}".format(required_platform, version),
            )
    for minor in MINOR_MAPPING:
        version = MINOR_MAPPING[minor]
        asserts.true(
            env,
            version in TOOL_VERSIONS.keys(),
            "Missing version {} in TOOL_VERSIONS".format(version),
        )
    return unittest.end(env)

# The unittest library requires that we export the test cases as named test rules,
# but their names are arbitrary and don't appear anywhere.
_t0_test = unittest.make(_smoke_test_impl)

def versions_test_suite(name):
    unittest.suite(name, _t0_test)


#!/usr/bin/env python
# coding: utf-8

# In[ ]:

# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the "../../../input/wenruliu_adult-income-dataset/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

import os
print(os.listdir("../../../input/wenruliu_adult-income-dataset"))

# Any results you write to the current directory are saved as output.

# In[ ]:

# Import the dataset
data = pd.read_csv("../../../input/wenruliu_adult-income-dataset/adult.csv")
data.head()

# We modify column names

# In[ ]:

my_columns = ['Age', 'Workclass', 'Fnlwgt', 'Education', 'Education_num', 'Martial_status', 'Occupation', 'Relationship', 'Race', 'Gender', 'Capital_gain','Capital_loss', 'hours_per_week', 'Native_country','Target']
data.columns = my_columns
data.head()

# In[ ]:

# Check the data type of each column and number of rows and columns present in the dataset
print(data.info())
print(data.shape)

# We can see there are 48842 rows and 15 columns. Some of the variables are continous and while others are categorical.

# In[ ]:

# Check whether there are any missing values
col_names = data.columns
num_data = data.shape[0]
for c in col_names:
    num_non = data[c].isin(["?"]).sum()
    if num_non > 0:
        print (c)
        print (num_non)
        print ("{0:.2f}%".format(float(num_non) / num_data * 100))
        print ("\n")

# In[ ]:

new_data = data
new_data.head()

# In[ ]:

from scipy.stats import mode
var = new_data.Workclass.mode()[0]
new_data.loc[new_data['Workclass'] == '?', 'Workclass'] = var

var1 = new_data.Occupation.mode()[0]
new_data.loc[new_data['Occupation'] == '?', 'Occupation'] = var1

var2 = new_data.Native_country.mode()[0]
new_data.loc[new_data['Native_country'] == '?', 'Native_country'] = var2
new_data.head()

# Now all the missing values are replaced by mode of the column

# EDA

# In[ ]:

my_tab = pd.crosstab(index = data.Education,   columns= data.Target)

my_tab.plot.bar()

# In[ ]:

my_tab = pd.crosstab(index = data.Race,   columns= data.Target)

my_tab.plot.bar()

# In[ ]:

my_tab = pd.crosstab(index = data.Martial_status,   columns= data.Target)

my_tab.plot.bar()

# In[ ]:

my_tab = pd.crosstab(index = data.Native_country,   columns= data.Target)

my_tab.plot.bar()

#

# **Feature Encoding**

# In[ ]:

from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import Imputer
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
Workclass_cat = le.fit_transform(new_data.Workclass)
Education_cat = le.fit_transform(new_data.Education)
Marital_cat   = le.fit_transform(new_data.Martial_status)
Occupation_cat = le.fit_transform(new_data.Occupation)
Relationship_cat = le.fit_transform(new_data.Relationship)
Race_cat = le.fit_transform(new_data.Race)
Sex_cat = le.fit_transform(new_data.Gender)
Native_country_cat = le.fit_transform(new_data.Native_country)
Target_cat = le.fit_transform(new_data.Target)

# In[ ]:

# Initialize the transformed values
new_data['Workclass'] = Workclass_cat
new_data['Education'] = Education_cat
new_data['Martial_status'] = Marital_cat
new_data['Occupation'] = Occupation_cat
new_data['Race'] = Race_cat
new_data['Gender'] = Sex_cat
new_data['Native_country'] = Native_country_cat

# In[ ]:

#dummy_fields = ['Workclass', 'Education', 'Martial_status', 'Occupation', 'Race','Sex', 'Native_country']
new_data.head()

# In[ ]:

# split the target and predictor variables
X = new_data.iloc[:,[0,1,2,3,4,5,6,8,9,10,11,12,13]]
Y = new_data.iloc[:,14]
X.head()

# In[ ]:

# Split the dataset into train and test dataset

from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.25, random_state = 5)

# In[ ]:

# Pipe line for multimodeling
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, roc_auc_score

lr = LogisticRegression()
Lr_model = lr.fit(X_train, Y_train)
Y_pred = lr.predict(X_test)
acc_score_lr = accuracy_score(Y_test, Y_pred)
print(acc_score_lr)

# In[ ]:

DTC = DecisionTreeClassifier()
DTC_model = DTC.fit(X_train, Y_train)
Y_pred = DTC.predict(X_test)
acc_score_DTC = accuracy_score(Y_test, Y_pred)
print(acc_score_DTC)

# In[ ]:

RF = RandomForestClassifier(n_estimators=1000, n_jobs= 2, random_state= 5)
RF_model = RF.fit(X_train, Y_train)
Y_pred = RF.predict(X_test)
acc_score_RF = accuracy_score(Y_test, Y_pred)
print(acc_score_RF)

# In[ ]:

SVM = SVC()
SVM_model = SVM.fit(X_train, Y_train)
Y_pred = SVM.predict(X_test)
acc_score_SVM = accuracy_score(Y_test, Y_pred)
print(acc_score_SVM)

# In[ ]:


import os
from enum import Enum
from random import randrange

import numpy as np
import torch
from torch.utils.data import Dataset

class Mode(Enum):
    TRAIN = 1
    VALIDATION = 2
    TEST = 3

class MidiClassicMusic(Dataset):
    """
    MidiClassicMusic dataset for PyTorch
    """
    def __init__(self, always_same_label= None, folder_path="./data/midi_files_npy_8_40", composers=['Brahms'],
                 mode=Mode.TRAIN, slices=7, add_noise=True, unsqueeze=True, cv_cycle=0):
        """
        :param folder_path: The folder in which the .npy files can be found
        :param composers: A list of names of composers that should be loaded
        :param mode: How this dataset is used train/validation/test
        :param slices: The amount of slices that should be concatenated for one data sample
        :param add_noise: When True some extra noise is added to the data samples
        :param unsqueeze: When using a CNN the input should be in the form of [height, width, channels],
        when unsqueeze is True this dataset will output samples in that format otherwise just [height, width]
        :param cv_cycle: Which parts are currently train and which are validation
        """
        self.slices = slices
        self.mode = mode
        self.composers = composers
        self.amount_of_composers = len(composers)
        self.data_array, self.song_idxs_array = self.load_npy_files(folder_path, cv_cycle)
        self.add_noise = add_noise
        self.unsqueeze = unsqueeze
        self.always_same_label = always_same_label

        # if self.mode != Mode.TRAIN:
        self.songs_to_simple_dataset_for_validations(step_size=int(self.slices / 8) if self.mode != mode.TRAIN else 1)

    def __len__(self):
        # if self.mode == Mode.TRAIN:
        #     return 4000
        # else:
        return len(self.validation_labels)

    @staticmethod
    def get_song_slices(composer_array, song_idxs, song_idx):
        song_start = song_idxs[song_idx]
        song_length_in_slices = song_idxs[song_idx+1] - song_start if song_idx+1 < len(song_idxs) else len(composer_array) - song_start
        return composer_array[song_start:song_start + song_length_in_slices], song_length_in_slices

    def get_train_item(self, index):
        index = index % self.amount_of_composers
        song_idxs = self.song_idxs_array[index]
        composer_data = self.data_array[index]

        amount_of_songs = len(song_idxs)
        song_length_in_slizes = 0
        while song_length_in_slizes <= self.slices:
            song_slices, song_length_in_slizes = self.get_song_slices(composer_data, song_idxs, randrange(amount_of_songs))

        start_of_part = randrange(song_length_in_slizes - self.slices)
        song_image = np.concatenate(song_slices[start_of_part:start_of_part + self.slices], axis=1)
        if self.add_noise:
            song_image += np.random.normal(loc=0, scale=0.01, size=song_image.shape)  # Add some noise

        torch_data = torch.from_numpy(song_image).float()
        return torch_data, index

    def get_validation_item(self, index):
        torch_data = torch.from_numpy(self.data_array[index]).float()
        return torch_data, self.validation_labels[index]

    def __getitem__(self, index):
        # if self.mode == Mode.TRAIN:
        #     torch_data, label = self.get_train_item(index)
        # else:
        torch_data, label = self.get_validation_item(index)

        if self.unsqueeze:
            torch_data = torch_data.unsqueeze(0)

        return torch_data, self.always_same_label if self.always_same_label else label

    def load_npy_files(self, folder_path, cv_cycle):
        data_filenames = ["{}_data.npy".format(composer) for composer in self.composers]
        data_array = []
        song_idxs_array = []

        for data_filename in data_filenames:
            songs = np.load(os.path.join(folder_path, data_filename))
            song_idx_filename = "{}_song_idxs.npy".format(data_filename.split('_')[0])
            song_idxs = np.load(os.path.join(folder_path, song_idx_filename))

            # Remove songs smaller than the input of the network
            songs, song_idxs = self.remove_to_small_songs(songs, song_idxs)
            # Split data in to cross_validation data and test_data
            cv_songs, cv_song_idxs, test_songs, test_song_idxs = self.take_out_every_nth_song(songs, song_idxs, 10)

            if self.mode == Mode.TEST:
                data_array.append(test_songs)
                song_idxs_array.append(test_song_idxs)
            else:
                # Cycle the song array
                amount_of_cycled_slices = cv_song_idxs[cv_cycle]
                slices_in_first_part = cv_songs[amount_of_cycled_slices:].shape[0]
                cv_songs = np.concatenate((cv_songs[amount_of_cycled_slices:], cv_songs[:amount_of_cycled_slices]), axis=0)

                # Cycle the idxs array
                first_part = cv_song_idxs[cv_cycle:] - amount_of_cycled_slices
                last_part = cv_song_idxs[:cv_cycle] + slices_in_first_part
                cv_song_idxs = np.concatenate((first_part, last_part))

                # Take every 4th for the validation
                train_songs, train_song_idxs, validation_songs, validation_song_idxs = self.take_out_every_nth_song(cv_songs, cv_song_idxs, 4)
                if self.mode == Mode.TRAIN:
                    data_array.append(train_songs)
                    song_idxs_array.append(train_song_idxs)
                else:
                    data_array.append(validation_songs)
                    song_idxs_array.append(validation_song_idxs)

        return data_array, song_idxs_array

    def songs_to_simple_dataset_for_validations(self, step_size):
        # For validation data we keep it a little bit simpler
        validation_data = []
        self.validation_labels = []
        for composer_idx, song_idxs in enumerate(self.song_idxs_array):
            for song_idx in range(len(song_idxs)):
                song_slices, length = self.get_song_slices(self.data_array[composer_idx], song_idxs, song_idx)
                slice_idx = 0
                while (slice_idx + self.slices) < length:
                    validation_data.append(np.concatenate(song_slices[slice_idx:slice_idx + self.slices], axis=1))
                    self.validation_labels.append(composer_idx)
                    slice_idx += step_size
        self.data_array = np.array(validation_data)

    def find_to_small_song(self, songs, song_idxs):
        for song_idx, song_start in enumerate(song_idxs):
            song_length_in_slices = song_idxs[song_idx + 1] - song_start if song_idx + 1 < len(song_idxs) else len(
                songs) - song_start
            if song_length_in_slices < self.slices:
                return song_idx
        return None

    @staticmethod
    def remove_song(song_idx, songs, song_idxs):
        """
        :param song_idx: The index of the song to be removed
        :param songs: Song slices array of one composer
        :param song_idxs: The start of every song in the songs array
        :return: songs and song_idxs but with the song_idxth song removed
        """
        if song_idx + 1 < len(song_idxs):  # We are not at the end of the array
            song_length = song_idxs[song_idx + 1] - song_idxs[song_idx]
        else:
            song_length = len(songs) - song_idxs[song_idx]
        songs = np.concatenate((songs[:song_idxs[song_idx]], songs[song_idxs[song_idx] + song_length:]), axis=0)
        song_idxs = np.concatenate((song_idxs[:song_idx], song_idxs[song_idx + 1:] - song_length))
        return songs, song_idxs

    def remove_to_small_songs(self, songs, song_idxs):
        song_to_be_removed = self.find_to_small_song(songs, song_idxs)
        while song_to_be_removed is not None:
            songs, song_idxs = self.remove_song(song_to_be_removed, songs, song_idxs)
            song_to_be_removed = self.find_to_small_song(songs, song_idxs)
        return songs, song_idxs

    def take_out_every_nth_song(self, songs, song_idxs, n):
        nth_songs = None
        nth_song_idxs = []
        for idx in range(len(song_idxs)-1, -1, -1):  # Walk through the array backwards
            if idx % n == 0:
                nth_song_idxs.append(0 if nth_songs is None else nth_songs.shape[0])
                nth_song = songs[song_idxs[idx]:song_idxs[idx+1]] if idx + 1 < len(song_idxs) else songs[song_idxs[idx]:len(songs)]
                nth_songs = nth_song if nth_songs is None else np.concatenate((nth_songs, nth_song))
                songs, song_idxs = self.remove_song(idx, songs, song_idxs)
        return songs, song_idxs, nth_songs, np.array(nth_song_idxs)


# -*- coding: utf-8 -*-
"""
Created on Mon Jun 26 12:03:53 2017

@author: AE
"""

import pandas as pd

def _extract_brut_from_row(mot, row):
    temp = row['text'][row['idx'] + len(mot) :row['idx'] + 50]
    temp = temp.lstrip()
    if temp[:2] == 'ES':
        temp = temp[2:]
    if temp[:1] == 'E':
        temp = temp[1:]
    temp = temp.lstrip()
    if temp[:1] == ':':
        temp = temp[1:]
    temp = temp.lstrip()
    return temp

def extract_apres_mot(mot, serie):
    ''' index est là lorsque le mot apparait plusieurs fois '''
    serie_lower = serie.str.lower()

    result_index = serie_lower.str.find(mot.lower())
    tab = pd.DataFrame({'text': serie, 'idx':result_index})

    extract_brut = tab.apply(lambda x: _extract_brut_from_row(mot, x), axis=1)

    # pour appelant

    stop_words = [',', '.', '\n', ':', '\(', '\)', 'à', ';', 'comme']
    extract = extract_brut
    for words in stop_words:
        extract = extract.str.split(words).str[0]

    return extract

select_from_jurinet = [
            'NUM_DECISION', 'NUMPOURVOI', 'ID_DOCUMENT',
            'JURIDICTION', 'ID_CHAMBRE', 'CHAMBRE', 'CAT_PUB', 'CHAMBRE',
            'ID_SOLUTION', 'SOLUTION', 'DT_DECISION',

            'COMPOSITION',
            'PRESIDENT', 'CONSRAP', 'AVOCAT', 'AVOG',
            ]

def csv_from_jurinet(jurinet):
    output = jurinet.copy()
    del output['TEXTE_ARRET']

    output.drop(['DT_MODIF', 'DT_CREATION',
                 'CLEF_ARRET',
                 ], axis=1, inplace=True)

    return output.loc[:, select_from_jurinet]

def exploitation(jurinet):
    output = jurinet.copy()
    text = output['TEXTE_ARRET']
    del output['TEXTE_ARRET']

    output = output.loc[:, select_from_jurinet]

    words = ['société', 'appelant', 'qualité de', 'salaire de']
    for word in words:
        output[word] = extract_apres_mot(word, text)

    return output

if __name__ == '__main__':
    from load_data import jurinet_2015_prudhom
    jurinet = jurinet_2015_prudhom()
    tt = exploitation(jurinet)


from django.urls import path, include
from .api import views
from . import views as v

urlpatterns = [
    path('api/',include('task.api.urls')),
    path('',v.task_show, name='task_show'),
    path('add/',v.add_task, name='add_task'),
    path('<int:pk>/',v.delete_task, name='delete'),
    path('complete/<int:pk>/',v.completed, name='complete'),
    path('searching/',v.Searching, name='search'),
    path('filtering/',v.filtering, name='filter'),
]


import xml.etree.ElementTree as ET
from collections import defaultdict

tree = ET.parse('newsafr.xml')
root = tree.getroot()

def list_news(): # Функция получения списка слов новостей
    str_news = ''
    list_word_news = []
    i = 0
    for i in range(len(root[0])-6):
        str_news += root[0][i+6][2].text + ' '
        i += 1
    list_news = str_news.split()
    for word in list_news:
        word = word.lower()
        if len(word) > 6:
            list_word_news.append(word)
        else:
            continue
    return list_word_news

def sort_dict_word(list_word_6c = list_news()):
    dict_no_sort = defaultdict(int) # Словарь слов, где ключ слово, значение количество его в новостях
    for word in list_word_6c:
        dict_no_sort[word] += 1
    dict_no_sort = dict(dict_no_sort)
    sort_list_word = list(dict_no_sort.values())
    sort_list_word.sort()
    sort_list_word.reverse()
    sort_list_word = sort_list_word[:10] # Сортированный по убыванию список количество слов
    sort_dict_10 = {} # Словарь слова и количество его в новотях
    for count in sort_list_word:
        for item in dict_no_sort:
            if count == dict_no_sort[item]:
                sort_dict_10[item] = count
            if len(sort_dict_10.keys()) == 10:
                break
            else:
                continue
    return sort_dict_10

def results(sort_dict_word = sort_dict_word(list_word_6c = list_news())):
    print('Перечень часто встречающихся слов в новостях и их количество, в порядке убывания: ')
    for key in sort_dict_word:
        print(f'{key} : {sort_dict_word[key]}')

results()


import torch
import torch.optim as optim
import helpers
import trainer.observers as observers
import copy

def train_network(network, config, observer=observers.EmptyObserver()):
    device = helpers.get_device()
    network.to(device)
    optimizer = optim.SGD(network.parameters(), lr=config.lr, momentum=config.momentum)
    min_loss = float('inf')
    min_loss_network = None
    for epoch in range(config.epochs):
        for iteration, data in enumerate(config.train_set_loader, 0):
            inputs, labels = data[0].to(device), data[1].to(device)
            optimizer.zero_grad()
            outputs = network(inputs)
            loss = config.criterion(outputs, labels)
            loss.backward()
            optimizer.step()
            observer.update(network, epoch, iteration, loss.item())
        validation_loss, validation_accuracy = get_validation_stats(
            network=network,
            validation_set_loader=config.validation_set_loader,
            criterion=config.criterion
        )
        observer.validation_update(network, epoch, validation_loss, validation_accuracy)
        if validation_loss < min_loss:
            min_loss = validation_loss
            min_loss_network = copy.deepcopy(network)
        if validation_loss / min_loss > 1.2:
            return min_loss_network
    return min_loss_network

def get_validation_stats(network, validation_set_loader, criterion):
    device = helpers.get_device()
    network.to(device)
    correct = 0
    total = 0
    loss = 0
    with torch.no_grad():
        for data in validation_set_loader:
            inputs, labels = data[0].to(device), data[1].to(device)
            outputs = network(inputs)
            _, predicted = torch.max(outputs, 1)
            loss_val = criterion(outputs, labels)
            loss += loss_val.item()
            total += labels.size(0)
            correct += (predicted == labels).sum().item()
    return loss, correct / total


# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

class Migration(migrations.Migration):

    dependencies = [
        ('watchstore', '0003_auto_20160413_2007'),
    ]

    operations = [
        migrations.AddField(
            model_name='men',
            name='style',
            field=models.CharField(default='', max_length=10, choices=[(b'Casual', b'Casual'), (b'Sporty', b'Sporty')]),
            preserve_default=False,
        ),
    ]


from crypto import crypto

KEYS_FILENAME = 'wallet_keys.txt'

class Wallet:
    def __init__(self):
        self.private_key = None
        self.public_key = None

    def create_keys(self):
        print('Creating public and private wallet keys...')
        self.private_key, self.public_key = crypto.generate_keys()
        #  save keys in this method
        #  new endpoint for getting keys?

    def save_keys(self):
        try:
            print('Saving wallet keys to a file...')
            with open(KEYS_FILENAME, mode='w') as file:
                file.write(self.private_key)
                file.write('\n')
                file.write(self.public_key)
                print('Successfully saved wallet keys to a file')
            return True
        except (IOError, IndexError):
            print('Saving wallet keys failed!')
            return False

    def load_keys(self):
        try:
            print('Loading wallet keys from a file...')
            with open(KEYS_FILENAME, mode='r') as file:
                keys = file.readlines()
                self.private_key = keys[0][:-1]  # exclude \n
                self.public_key = keys[1]
        except (IOError, IndexError):
            print('Loading wallet keys failed!')

    def sign_transaction(self, sender, recipient, amount):
        print(f'Signing new transaction from {sender} to {recipient}...')
        payload = f'{sender}{recipient}{amount}'
        return crypto.generate_signature(self.private_key, payload)

    @staticmethod
    def verify_transaction(transaction):
        payload = f'{transaction.sender}{transaction.recipient}{transaction.amount}'
        return crypto.verify_signature(transaction.sender, payload, transaction.signature)


from sqlitedict import SqliteDict
import math

# Url -> PageID
url2pageID = SqliteDict('./db/url2pageID.sqlite')
# PageID -> {WordID: frequency, ... }
forwardIndex = SqliteDict('./db/forwardIndex.sqlite')
# PageID -> doc_norm
docNorm = SqliteDict('./db/docNorm.sqlite')
# WordID -> [[PageID, frequency, tf_idf]]
invertedIndex = SqliteDict('./db/invertedIndex.sqlite')
# PageID -> [TitleID]
forwardIndexTitle = SqliteDict('./db/forwardIndexTitle.sqlite')
# TitleID -> [PageID, tf_idf]
invertedIndexTitle = SqliteDict('./db/invertedIndexTitle.sqlite')
# PageID -> title_norm
titleNorm = SqliteDict('./db/titleNorm.sqlite')

def comp_tf_idf():
    total_doc_no = float(len(url2pageID))
    i = 0
    for word_id, posting_list in invertedIndex.items():
        print(i, len(invertedIndex))
        i += 1
        df = float(len(posting_list))
        idf = math.log(total_doc_no / df, 2)
        # tf_max = float(max([x[1] for x in posting_list]))
        for idx in range(len(posting_list)):
            page_id = posting_list[idx][0]
            tf_max = max(list(forwardIndex[page_id].values()))
            tf = float(posting_list[idx][1])
            tf_idf = tf / tf_max * idf
            posting_list[idx][2] = tf_idf
        invertedIndex[word_id] = posting_list

def comp_doc_norm():
    i = 0
    for doc_id, forward_dict in forwardIndex.items():
        print(i, len(forwardIndex))
        i += 1
        word_list = list(forward_dict.keys())
        doc_norm = 0
        for word_id in word_list:
            posting_list = invertedIndex[word_id]
            doc_list = [p_l[0] for p_l in posting_list]
            index = doc_list.index(int(doc_id))
            tf_idf = posting_list[index][2]
            doc_norm += tf_idf * tf_idf
        doc_norm = math.sqrt(doc_norm)
        docNorm[doc_id] = doc_norm

def comp_tf_idf_title():
    total_doc_no = float(len(url2pageID))
    i = 0
    for word_id, posting_list in invertedIndexTitle.items():
        print(i, len(invertedIndexTitle))
        i += 1
        df = float(len(posting_list))
        idf = math.log(total_doc_no / df, 2)
        # tf_max = float(max([x[1] for x in posting_list]))
        for idx in range(len(posting_list)):
            # tf = float(posting_list[idx][1])
            # tf_idf = tf / tf_max * idf
            tf_idf = 1 * idf
            posting_list[idx][1] = tf_idf
        invertedIndexTitle[word_id] = posting_list

def comp_title_norm():
    i = 0
    for doc_id, forward_list in forwardIndexTitle.items():
        print(i, len(forwardIndexTitle))
        i += 1
        word_list = forward_list
        title_norm = 0
        for word_id in word_list:
            posting_list = invertedIndexTitle[word_id]
            doc_list = [p_l[0] for p_l in posting_list]
            index = doc_list.index(int(doc_id))
            tf_idf = posting_list[index][1]
            title_norm += tf_idf * tf_idf
        title_norm = math.sqrt(title_norm)
        titleNorm[doc_id] = title_norm

comp_tf_idf()
comp_doc_norm()
comp_tf_idf_title()
comp_title_norm()
# print(invertedIndex)
# x = dict(invertedIndex.items())

invertedIndex.commit()
docNorm.commit()
invertedIndexTitle.commit()
titleNorm.commit()

url2pageID.close()
forwardIndex.close()
forwardIndexTitle.close()

invertedIndex.close()
docNorm.close()
invertedIndexTitle.close()
titleNorm.close()


"""issue_references

Revision ID: 79c64025f7cf
Revises: 8a14e99b6079
Create Date: 2023-03-21 14:06:04.020963

"""
from alembic import op
import sqlalchemy as sa

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "79c64025f7cf"
down_revision = "8a14e99b6079"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None

def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "issue_references",
        sa.Column("issue_id", sa.UUID(), nullable=False),
        sa.Column("pull_request_id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("modified_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.ForeignKeyConstraint(
            ["issue_id"],
            ["issues.id"],
        ),
        sa.ForeignKeyConstraint(
            ["pull_request_id"],
            ["pull_requests.id"],
        ),
        sa.PrimaryKeyConstraint("issue_id", "pull_request_id"),
    )
    # ### end Alembic commands ###

def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("issue_references")
    # ### end Alembic commands ###


import io
import zipfile

import pandas as pd
import pytest
import requests
from bs4 import BeautifulSoup

from oda_data import config
from oda_data.get_data import common

def test__checktype():
    expected_int = [1, 2, 3]
    expected_float = [1.0, 2.0, 3.0]

    tests = [[1, 2, 3], ["1", "2", "3"], [1.0, 2.0, 3.0]]

    for test in tests:
        assert common._checktype(test, int) == expected_int
        assert common._checktype(test, float) == expected_float

    assert common._checktype("1", int) == [1]
    assert common._checktype(1, int) == [1]
    assert common._checktype(1.0, int) == [1]
    with pytest.raises(ValueError):
        common._checktype((1, 2, 3), int)

def test_check_integers():
    tests = [[1, 2, 3], ["1", "2", "3"], [1.0, 2.0, 3.0]]
    for test in tests:
        assert common.check_integers(test) == [1, 2, 3]

    assert common.check_integers(range(2020, 2022)) == [2020, 2021]

def test_get_zip():
    """This function is essentially just a wrapper around requests.get"""
    # TODO: work on a test
    assert True

def test__serialise_content():
    with open(config.OdaPATHS.test_files / "zip_response", "rb") as f:
        response = f.read()

    mock_response = requests.Response()
    mock_response._content = response

    assert isinstance(common._serialise_content(mock_response), io.BytesIO)

def test__extract_zip():
    with open(config.OdaPATHS.test_files / "zip_response", "rb") as f:
        response = f.read()

    mock_response = requests.Response()
    mock_response._content = response

    serialised = common._serialise_content(mock_response)

    file = common._extract_zip(serialised, "Table1_Data.csv")

    assert isinstance(file, zipfile.ZipExtFile)

def test__raw2df():
    file_comma = config.OdaPATHS.test_files / "comma_df_raw.csv"
    file_tab = config.OdaPATHS.test_files / "tab_df_raw.csv"

    df_comma = common._raw2df(file_comma, sep=",", encoding="ISO-8859-1")

    with pytest.raises(pd.errors.ParserError):
        common._raw2df(file_tab, sep="|", encoding="ISO-8859-1")

    assert isinstance(df_comma, pd.DataFrame)
    assert len(df_comma.columns) > 3

def test_read_zip_content():
    with open(config.OdaPATHS.test_files / "zip_response", "rb") as f:
        response = f.read()

    mock_response = requests.Response()
    mock_response._content = response

    result = common.read_zip_content(
        request_content=mock_response, file_name="Table1_Data.csv", priority_sep=","
    )

    assert isinstance(result, pd.DataFrame)

def test__links_dict():
    with open(config.OdaPATHS.test_files / "response_multi", "r") as f:
        response = f.read()

    soup = BeautifulSoup(response, "html.parser")
    results_set = soup.find_all("a")

    links = common._links_dict(results_set)

    assert isinstance(links, dict)
    assert len(links) == 21
    assert links.get(2021) is not None


#-*- coding: utf-8 -*-

import numpy as np
import pydotplus.graphviz as gv

class SimpleWeb(object):
    def __init__(self, nombreSommet):
        """ on crée des noeuds lors de l'initialisation"""
        self.nombreSommet = nombreSommet
        self.listeSommet = []
        self.arcExistant = set()
        for i in range(0,nombreSommet):
            n = Node(i)
            self.listeSommet.append(n)
        self.matriceProba = np.zeros((nombreSommet, nombreSommet))
        self.nb_pas = None
        self.fichier = None

    def addArc(self,id_n1,id_n2):
        """ id_n1(tail) : int, id_n2(head) : int -> ajoute les arc aux sommets référencés"""
        if id_n1 == id_n2:
            raise Exception("meme noeud")
        if (id_n1, id_n2) in self.arcExistant:
            raise Exception("l'arc existe deja")
        self.arcExistant.add((id_n1,id_n2))
        n1 = self.listeSommet[id_n1]
        n2 = self.listeSommet[id_n2]
        #print("on ajoute un arc de {} vers {}".format(n1,n2))
        a = Arc(id_n1,id_n2)
        n2.ajoute_arc_entrant(a)
        n1.ajoute_arc_sortant(a)
        self.updateProbas()

    def updateProbas(self):
        """ on parcourt tous les noeuds et incremente a partir des arcs entrants"""
        for i in range(0,self.nombreSommet):
            n = self.listeSommet[i]
            #le noeud n'a aucun arc
            if len(n.arcSortant) == 0:
                self.matriceProba[i][i] = 1
            #si il a un nouvelle arc, on supprime l'arc pointant vers lui meme
            if len(n.arcSortant) == 1 and self.matriceProba[i][i] == 1:
                self.matriceProba[i][i] = 0
            for arc in n.arcSortant:
                head = arc.head
                tail = arc.tail
                arc.proba = 1 / (len(n.arcSortant)*1.0)
                self.matriceProba[tail][head] = arc.proba

    def __str__(self):
        s =  "MatriceProba : {} \n".format(self.matriceProba)
        for i in range(self.nombreSommet):
            n = self.listeSommet[i]
            if not(n.arcSortant_vide()):
                s += n.__str__()
        return s

    def writeGraph(self, fichier):
        ''' fichier : nom du fichier dans le repertoire courant '''
        graph = gv.Dot(graph_type='digraph')
        for node in self.listeSommet:
            graph.add_node(gv.Node(node.id_node))
        for node in self.listeSommet:
            for arc in node.arcSortant:
                graph.add_edge(gv.Edge(node.id_node, arc.head, label=arc.proba))
        graph.write_png(fichier)

    def nextStep(self,pi_t):
        """ np.array -> np.array"""
        return np.dot(pi_t,self.matriceProba)

    def convergence_p(self, iterMax, seuil):
        """ p : matriceProba"""
        matricePuissante = np.copy(self.matriceProba)
        cpt = 0
        epsilon = 1
        while epsilon > seuil and cpt < iterMax:
            newPuissance = np.dot(matricePuissante, self.matriceProba)
            dif = abs(matricePuissante - newPuissance)
            epsilon = np.amax(dif)
            if self.nb_pas != None and self.fichier != None:
                if cpt % self.nb_pas == 0 and cpt != 0:
                    self.ecrit(cpt, epsilon)
                    #print("epsilon : {}".format(epsilon))
            matricePuissante = newPuissance
            cpt += 1

        print("\n------- PUISSANCES -------")
        print("iterations : {}".format(cpt))
        print("epsilon : {}\n".format(epsilon))
        return matricePuissante

    def trace(self, nb_pas, fichier):
        self.nb_pas = nb_pas
        self.fichier = fichier
        #on supprime l'ancienne valeur
        f = open(self.fichier, 'w')
        f.close()

    def ecrit(self, nb, epsilon):
        #on crée les nouvelles valeurs
        f = open(self.fichier, 'a')
        e = (str)(epsilon)
        f.write(str(nb) + ' ' + e + '\n')
        f.close()

class Node(object):
    def __init__(self,id_node):
        """ int * Arc[] * Arc[] -> void
        si un noeud n'a pas d'arc sortant, on place un arc vers lui meme avec une proba 1 """
        self.arcSortant = []
        self.arcEntrant = []
        self.id_node = id_node

    def arcSortant_vide(self):
        if self.arcSortant == []:
            return True
        return False

    def ajoute_arc_sortant(self,arc):
        self.arcSortant.append(arc)

    def ajoute_arc_entrant(self,arc):
        self.arcEntrant.append(arc)

    def __str__(self):
        s =  "Noeud numero : {} \n ".format(self.id_node)
        #print("liste des arc sortant : ",self.arcSortant)
        if self.arcSortant != []:
            s += "Arc sortant : \n"
            for arc in self.arcSortant:
                s += '\t' + arc.__str__() + '\n'
        return s

class Arc(object):
    def __init__(self,tail, head, proba=0):
        self.tail = tail
        self.head = head
        self.proba = proba

    def __str__(self):
        return "Arc du noeud : {} vers le noeud {} avec une probabilité : {}".format(self.tail, self.head,self.proba)


import frappe
from frappe.utils import nowdate
from frappe import get_print

def get_context(context):
    context.cart_items = frappe.get_all(
        'Shopping Cart', fields=['image', 'item_name', 'price', 'route', 'quantity'])
    context.sum = frappe.get_all('Shopping cart', fields=[
                                 'sum(price*quantity) as sum'])
    return context

@frappe.whitelist(allow_guest=True)
def remove_item_from_cart(name):
    frappe.delete_doc('Shopping Cart', name, ignore_permissions=True)

@frappe.whitelist(allow_guest=True)
def create_sales_invoice(user: str):
    try:
        frappe.get_doc("Person", user)
    except:
        create_customer(user)
    # parties = frappe.get_doc("Person",user)
    # print("*\n"*10,parties.as_dict(),"\n*"*10)
    # return parties.as_dict()
    # parties = frappe.get_doc("Person", user)
    cart_items = frappe.get_all("Shopping Cart", [
        '(item_name) as item', '(price) as rate', 'quantity', '(price*quantity) as total'])
    sales_invoice = frappe.get_doc({
        "doctype": "Sales Invoice",
        "title": f"Sales Invoice - {nowdate()}",
        "posting_date": nowdate(),
        "party": user,
        "items": cart_items,
        "total": sum([item['total'] for item in cart_items])
    })
    sales_invoice.insert(ignore_permissions=True)
    sales_invoice.submit()
    return sales_invoice.as_dict()

@frappe.whitelist(allow_guest=True)
def create_customer(name: str) -> str:
    party = frappe.get_doc({
        "doctype": "Person",
        "party_name": name,
        "type": "Customer"
    })
    party.insert(ignore_permissions=True)
    return party.party_name


lst = [4,8,12,98,50]

it = iter(lst)
print('Iterator Values: without for loop - ')
print(it.__next__())
print(it.__next__())
print(next(it))
print('Iterator Values: with for loop - ')
for i in it:
    print(i)

## User-defined iterator
class iterSeq:
    def __init__(self):
        self.x = 1

    def __iter__(self):
        #self.x = 1       ## u can initialise it when u are not using init method.
        return self

    def __next__(self):
        if self.x <= 10:
            num = self.x
            self.x+=1
            return num
        else:
            raise StopIteration

it = iterSeq()
#it.__iter__()
print('User-defined Iterator Values: without for loop - ')
print(it.__next__())
print(next(it))

print('User-defined Iterator Values: with for loop - ')
for i in it:
    print(i)


class Location(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def move(self, deltaX, deltaY):
        return Location(self.x + deltaX, self.y + deltaY)

    def getX(self):
        return self.x

    def getY(self):
        return self.y

    def distFrom(self, other):
        ox = other.x
        oy = other.y
        xDist = self.x - ox
        yDist = self.y - oy
        return (xDist**2 + yDist**2)**0.5

    def __str__(self):
        return '<' + str(self.x) + ', ' + str(self.y) + '>'

class Field(object):
    def __init__(self):
        self.drunks = {}

    def addDrunk(self, drunk, loc):
        if drunk in self.drunks:
            raise ValueError('Duplicate drunk')
        else:
            self.drunks[drunk] = loc

    def getLoc(self, drunk):
        if drunk not in self.drunks:
            raise ValueError('Drunk not in field')
        return self.drunks[drunk]

    def moveDrunk(self, drunk):
        if drunk not in self.drunks:
            raise ValueError('Drunk not in field')
        xDist, yDist = drunk.takeStep()
        currentLocation = self.drunks[drunk]
        self.drunks[drunk] = currentLocation.move(xDist, yDist)

class Drunk(object):
    def __init__(self, name = None):
        self.name = name

    def __str__(self):
        return 'This drunk is named ' + self.name

import random

class UsualDrunk(Drunk):
    def takeStep(self):
        stepChoices = \
            [(0.0, 1.0), (0.0, -1.0), (1.0, 0.0), (-1.0, 0.0)]
        return random.choice(stepChoices)

class ColdDrunk(Drunk):
    def takeStep(self):
        stepChoices = \
            [(0.0, 0.9), (0.0, -1.1), (1.0, 0.0), (-1.0, 0.0)]
        return random.choice(stepChoices)

def walk(f, d, numSteps):
    start = f.getLoc(d)
    for s in range(numSteps):
        f.moveDrunk(d)
    return start.distFrom(f.getLoc(d))

def simWalks(numSteps, numTrials, dClass):
    Homer = dClass()
    origin = Location(0, 0)
    distances = []
    for t in range(numTrials):
        f = Field()
        f.addDrunk(Homer, origin)
        distances.append(round(walk(f, Homer, numSteps), 1))
    return distances

def drunkTest(walkLengths, numTrials, dClass):
    for numSteps in walkLengths:
        distances = simWalks(numSteps, numTrials, dClass)
        print(dClass.__name__, 'random walk of', numSteps, 'steps')
        print(' Mean = ', round(sum(distances)/len(distances), 4))
        print(' Max = ', max(distances), 'Min = ', min(distances))

def simAll1(drunkKinds, walkLengths, numTrials):
    for dClass in drunkKinds:
        drunkTest(walkLengths, numTrials, dClass)

class styleIterator(object):
    def __init__(self, styles):
        self.index = 0
        self.styles = styles

    def nextStyle(self):
        result = self.styles[self.index]
        if self.index == len(self.styles) - 1:
            self.index = 0
        else:
            self.index += 1
        return result

def simDrunk(numTrials, dClass, walkLengths):
    meanDistances = []
    for numSteps in walkLengths:
        print('Starting simulation of', numSteps, 'steps')
        trials = simWalks(numSteps, numTrials, dClass)
        mean = sum(trials)/len(trials)
        meanDistances.append(mean)
    return meanDistances

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

def simAll(drunkKinds, walkLengths, numTrials):
    styleChoice = styleIterator(('m-', 'b--', 'g-.'))
    for dClass in drunkKinds:
        curStyle = styleChoice.nextStyle()
        print('Starting simulation of', dClass.__name__)
        means = simDrunk(numTrials, dClass, walkLengths)
        plt.plot(walkLengths, means, curStyle, label=dClass.__name__)

    plt.title('Mean Distance from Origin (' + str(numTrials) + ' trials)')
    plt.xlabel('Number of steps')
    plt.ylabel('Distance from Origin')
    plt.legend(loc = 'best')
    plt.show()

def getFinalLocs(numSteps, numTrials, dClass):
    locs = []
    d = dClass()
    for t in range(numTrials):
        f = Field()
        f.addDrunk(d, Location(0,0))
        for s in range(numSteps):
            f.moveDrunk(d)
        locs.append(f.getLoc(d))
    return locs

import numpy as np
def plotLocs(drunkKinds, numSteps, numTrials):
    styleChoice = styleIterator(('k+', 'r^', 'mo'))
    for dClass in drunkKinds:
        locs = getFinalLocs(numSteps, numTrials, dClass)
        xVals, yVals = [], []
        for loc in locs:
            xVals.append(loc.getX())
            yVals.append(loc.getY())
        xVals = np.array(xVals)
        yVals = np.array(yVals)
        meanX = sum(abs(xVals))/len(xVals)
        meanY = sum(abs(yVals))/len(yVals)

        curStyle = styleChoice.nextStyle()
        plt.plot(xVals, yVals, curStyle,
                   label=dClass.__name__ + \
                         ' mean abs dist = <'
                         + str(meanX) + ', ' + str(meanY) + '>')
    plt.ylim(-1000, 1000)
    plt.xlim(-1000, 1000)
    plt.show()

random.seed(0)
#drunkTest([10, 100, 1000, 10000], 100, UsualDrunk)
#simAll((UsualDrunk, ColdDrunk), (1, 10, 100, 1000, 10000), 100)

numSteps = (10, 100, 1000, 10000)
simAll((UsualDrunk, ColdDrunk), numSteps, 100)
plotLocs((UsualDrunk, ColdDrunk), 10000, 100)


"""
Queue data structure implementation using python list
Following methods of stacks are implemented, enqueue(item), dequeue(), peek()
"""

class queue():
    """
    class implementation of queue data structure
    """
    def __init__(self):
        """
        initialize the objects with empty list
        """
        self.__queue = []
        print("Queue is initialized.")

    def queue_size(self):
        """
        size of the queue
        :return int:
        """
        return len(self.__queue)

    def printQueue(self):
        """

        :return list:
        """
        return self.__queue[::-1]

    def enqueue(self,item):
        """

        :param item:
        :return boolean:
        """
        try:
            self.__queue.append(item)
            return True
        except:
            return False

    def dequeue(self):
        """

        :return item:
        """
        try:
            if self.queue_size() > 0:
                item = self.__queue[0]
                print(f"Item {item} is dequeued. New size of the queue is {self.queue_size()}")
                del self.__queue[0]
                return item
            else:
                print("Queue is empty.")
        except:
            return None

    def peek(self):
        """

        :return item:
        """
        try:
            if self.queue_size() > 0:
                print(f"Item {self.__queue[0]} is peeked.")
                return self.__queue[0]
            else:
                print("Queue is empty.")
        except:
            return None

if __name__ == "__main__":
    """
    """
    myqueue = queue()
    items_list = [22,33,44,55]
    for item in items_list:
        print(f"Item {item} queued. New size of the queue is {myqueue.queue_size()}") if myqueue.enqueue(item) else print("enqueuing failed")

    print(myqueue.printQueue())
    myqueue.dequeue()
    print(myqueue.printQueue())
    myqueue.peek()


import numpy as np
from glob import glob
import cv2
import scipy.io as sio
import imgvision as iv

class Dataloader():
    def __init__(self,args,keys=None,norm=True):
        self.keys = keys
        self.norm = norm
        self.Filelist =sorted(glob(args.path+'*.mat'))
    def load(self,index):

        self.Filename = self.Filelist[index].split('\\')[-1]
        base = sio.loadmat(self.Filelist[index])
        if self.keys is None:
            self.key = list(base.keys())[-1]

        Ground_Truth = base[self.keys]

        if self.norm is True:
            Ground_Truth = Ground_Truth/Ground_Truth.max()
            Ground_Truth = Ground_Truth[:1024,:1024]

        print('\nLoad {} Successfully\n'.format(self.Filelist[index].split('\\')[-1] ))
        return Ground_Truth,self.Filelist[index].split('\\')[-1]
    def save(self,args,img):
        np.save(args.save_path+self.Filename.replace('.mat',''),img)

def generate_lrhsi(gt,sf,type='Gaussian'):
    if type.lower()=='gaussian':
        return cv2.GaussianBlur(gt,(sf-1,sf-1),sf//4)[sf//2-1::sf,sf//2-1::sf]
    elif type.lower()=='motion':
        import paddleiv
        return paddleiv.get_LR(gt,type)

def generate_hrrgb(gt,srf):
    return gt @ srf

def get_pairs(gt,sf,srf,noise=None,NSR_HSI=30,NSR_RGB=40,b_type='gaussian'):
    lrhsi = generate_lrhsi(gt,sf)
    hrrgb = generate_hrrgb(gt,srf)
    if noise:
        lrhsi = iv.add_noise(lrhsi,NSR_HSI)
        hrrgb = iv.add_noise(hrrgb,NSR_RGB)

    print("\033[1;36m Image Settings \033[0m".center(61, '-'))
    print('\t\033[1;33m LR-HSI\t\tHR-RGB \033[0m'.ljust(50))
    print(f'size\t{lrhsi.shape}\t{hrrgb.shape}'.ljust(50))
    print(f'noise\t{noise}'.ljust(50))
    print(''.center(50,'-'))
    return lrhsi,hrrgb


import os
from io import BytesIO
from fastapi import APIRouter, UploadFile, File
from s3 import s3

router = APIRouter(prefix="/images", tags=["images"])
BUCKET_NAME = os.environ["BUCKET_NAME"]

# Upload image from mobile app to IBM Cloud Object Storage
@router.post("/", status_code=201)
async def upload_image(image: UploadFile = File(...)):
    key = os.path.basename(image.filename)
    url = f"{os.environ['ENDPOINT']}/{BUCKET_NAME}/{key}"
    try:
        contents = await image.read()
        with BytesIO(contents) as data:
            s3.upload_fileobj(data, BUCKET_NAME, key)
        print(f"Uploaded image {key}")
    except Exception as e:
        print(e)
        print(f"Failed to upload image {key}")

    return {"key": key, "url": url}

# Delete image from IBM Cloud Object Storage
@router.delete("/{key}", status_code=204)
def delete_image(key: str):
    try:
        s3.delete_object(Bucket=BUCKET_NAME, Key=key)
        print(f"Deleted image {key}")
    except Exception as e:
        print(e)
        print(f"Failed to delete image {key}")


import RPi.GPIO as GPIO
import time
chan_list = [26, 19, 13, 6, 5, 11, 9, 10, 17]
GPIO.setmode(GPIO.BCM)
GPIO.setup(chan_list, GPIO.OUT)

numbers={7:26, 6:19, 5:13, 4:6, 3:5, 2:11, 1:9, 0:10}

GPIO.output(17, 1)

def decToBinList(decNumber):
    s = []
    while decNumber > 0:
        s.append(decNumber % 2)
        decNumber //= 2
    while len(s) < 8:
        s.append(0)
    a = []
    for i in range(len(s) - 1, -1, -1):
        a.append(s[i])
    return s

def num2dec(value):
    k = decToBinList(value)
    for i in range(8):
        if k[i] == 1:
            GPIO.output(numbers[i],1)

try:
    while True:

        print('Enter value (-1 to exit)')
        i = int(input())
        if i == -1:
            break
        print(i ,' = ', round(3.3*(i/255),2) ,'V')
        GPIO.output(chan_list,0)
        GPIO.output(17,1)
        num2dec(i)
        time.sleep(0.1)
finally:
    GPIO.cleanup()


# Smallest Rotation With Highest Score

list1 = [2,3,1,4,0]
scores = []

def new_list_creator(list , k):
    Newlist = []
    difference = []
    current_score = 0

    while k < len(list):
            Newlist.append(list1[k])
            k +=1

    for i in range(len(list) - len(Newlist)):
        Newlist.append(list[i])

    for i in range(len(Newlist)):
        difference.append(Newlist[i] - i)

    for diff in difference:
        if(diff <= 0):
            current_score += 1

    scores.append(current_score)

for i in range(len(list1)):
    new_list_creator(list1 , i)

for score in scores:
    if(score == max(scores)):
        print(scores.index(score))
        break


# break and continue
# i = 10
i = 10_000
while True:
    print("i is", i) # this runs at least once
    if i > 20:
        print("time to break freeeeeee", i)
        break # goes to next line after while loop end
    i += 2
print("Outside loop")
# essentially we have just made a do while loop
# which runs at least one time and only then checks
# so to say 'shoot first and ask questions later'
# we also have less used construction continue - it goes to start of loop immediately

i = 10
while i < 20:
    print("i is", i)
    if i == 15:
        print("Oh special number", i)
        i += 3 # big jump here otherwise continue would be pointless
        continue # goes to start of while loop
    i += 1

# we also have a strange construction else attached to while loop!
# it works when no break was performed in the loop
i = 0
while i < 5:
    print("normal i", i)
    if i == 3:
        print("quick break", i)
        break # will cause else block not to run
    i += 1
else: # this will run only if no break was encounterd in while loop
    print("While loop run normally")
print("Always runs")


import ast
import sys

a = input()

arr = a.split(' ')

if len(arr) != 5:
    sys.exit('Некорректное выражение')

with open(r'index.json', 'r',
          encoding='utf-8') as file:
    index = ast.literal_eval(file.read())

all_values = set(range(1, 101))
all_values = set([str(i) for i in all_values])

new_arr = []

for i in range(len(arr)):
    if i % 2 == 0:
        if arr[i].startswith('!'):
            if index.get(arr[i][1:]) == None:
                sys.exit('Нет слов')

            new_arr.append(all_values - set(index.get(arr[i][1:])))
            arr[i] = arr[i][1:]
        else:
            if index.get(arr[i]) == None:
                sys.exit('Нет слов')
            new_arr.append(index.get(arr[i]))

if arr[1] == '|' or arr[1] == 'ИЛИ':
    if arr[3] == '|' or arr[3] == 'ИЛИ':
        result = set(new_arr[0]) | set(new_arr[1]) | set(new_arr[2])
    elif arr[3] == '&' or arr[3] == 'И':
        result = set(new_arr[0]) | set(new_arr[1]) & set(new_arr[2])
elif arr[1] == '&' or arr[1] == 'И':
    if arr[3] == '|' or arr[3] == 'ИЛИ':
        result = set(new_arr[0]) & set(new_arr[1]) | set(new_arr[2])
    elif arr[3] == '&' or arr[3] == 'И':
        result = set(new_arr[0]) & set(new_arr[1]) & set(new_arr[2])

if len(result) == 0:
    print("Не найдено")
else:
    with open(r'3rd_Task/result.txt', 'a',
        encoding='utf-8') as file:
        file.write(a + '\n')
        result = set([int(i) for i in result])
        sortedResult = sorted(result)
        for i, el in enumerate(sortedResult):
            if i == 0:
                file.write('[')
            if i == len(sortedResult) - 1:
                file.write(str(el) + ']' + '\n')
                continue
            file.write(str(el) + ', ')
        print(sortedResult)

# телефон & фонарь | звезда
# телефон | фонарь | звезда
# телефон & !фонарь | !звезда
# телефон | !фонарь | !звезда
# телефон И фонарь ИЛИ звезда
# телефон ИЛИ фонарь ИЛИ звезда
# телефон И !фонарь ИЛИ !звезда
# телефон ИЛИ !фонарь ИЛИ !звезда


'''

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.

'''
import numpy as np

i=0
prodVals = []
for val1 in range(100, 1000):
    for val2 in range(100, 1000):
        prodVals.append(val1 * val2)
        i += 1

prodVals = sorted(np.unique(prodVals), reverse=True)

i=1
isPal = False
while isPal == False:
    strProdVals = str(prodVals[i])
    i += 1
    if strProdVals[0:3] == strProdVals[3:6][::-1]:
        isPal = True


import torch
import torch.nn as nn
import torch.optim as optim
import pandas as pd
import zarr
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

# 1. Data Preparation
def read_cf_pair(dt, n):
    start, end = dt.index_range[n]
    timestamps = dt.timestamp[start:end]
    t = (timestamps-timestamps[0]) # read time and convert it to second

    lead_centroid = dt.lead_centroid[start: end]
    follow_centroid = dt.follow_centroid[start: end]
    follow_velocity = dt.follow_velocity[start: end]
    lead_velocity = dt.lead_velocity[start: end]
    follow_acceleration = dt.follow_acceleration[start: end]
    lead_acceleration = dt.lead_acceleration[start: end]
    # size_lead = dt.lead_size[n] # this is for HV
    size_lead = 4.8
    size_follow = dt.follow_size[n]

    return lead_centroid, follow_centroid, follow_velocity, follow_acceleration, lead_acceleration, lead_velocity, t, size_lead, size_follow

# For easier data manipulation, we convert the data into a pandas dataframe
# x_lead, x_follow, v_follow, a_follow, a_lead, v_lead, t, size_lead, size_follow = read_cf_pair(data, 120)

zarr_data = zarr.open('../data/valAV.zarr', mode='r')
data = pd.DataFrame(data=dict(zip(['x_lead', 'x_follow', 'v_follow', 'a_follow', 'a_lead', 'v_lead', 't', 'size_lead', 'size_follow'], read_cf_pair(zarr_data, 120))))

# Calculate spacing and relative speed
data['spacing'] = data['x_lead'] - data['x_follow'] - data['size_lead']
data['relative_speed'] = data['v_lead'] - data['v_follow']

# Select features and target
# features = data[['spacing', 'relative_speed', 'v_follow', 'v_lead', 'a_follow' ,'a_lead', 'x_lead']]
features = data[['spacing', 'relative_speed']]
target = data['a_follow']

# Normalize data
scaler = MinMaxScaler()
features = scaler.fit_transform(features)

# Split into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)

# Convert data to PyTorch tensors
X_train_tensor = torch.FloatTensor(X_train).unsqueeze(2)
y_train_tensor = torch.FloatTensor(y_train.values)
X_test_tensor = torch.FloatTensor(X_test).unsqueeze(2)
y_test_tensor = torch.FloatTensor(y_test.values)

# 2. Model Definition
class CarFollowingLSTM(nn.Module):
    def __init__(self, input_dim, hidden_dim, num_layers, output_dim):
        super(CarFollowingLSTM, self).__init__()
        self.hidden_dim = hidden_dim
        self.num_layers = num_layers
        self.lstm = nn.LSTM(input_dim, hidden_dim, num_layers, batch_first=True)
        self.linear = nn.Linear(hidden_dim, output_dim)

    def forward(self, x):
        h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_dim).requires_grad_()
        c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_dim).requires_grad_()
        out, (hn, cn) = self.lstm(x, (h0.detach(), c0.detach()))
        out = self.linear(out[:, -1, :])
        return out

input_dim = 1
hidden_dim = 32
num_layers = 2
output_dim = 1

model = CarFollowingLSTM(input_dim=input_dim, hidden_dim=hidden_dim, num_layers=num_layers, output_dim=output_dim)

# 3. Training
loss_function = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

num_epochs = 100
for epoch in range(num_epochs):
    model.train()
    optimizer.zero_grad()
    outputs = model(X_train_tensor)
    loss = loss_function(outputs, y_train_tensor)
    loss.backward()
    optimizer.step()
    if epoch % 10 == 0:
        print(f'Epoch {epoch}, Loss: {loss.item()}')

# 4. Saving
torch.save(model.state_dict(), 'car_following_model.pth')

# 5. Evaluation
model.eval()
test_outputs = model(X_test_tensor)
test_loss = loss_function(test_outputs, y_test_tensor)
print(f'Test Loss: {test_loss.item()}')

y_pred = test_outputs.detach().numpy()
y_true = y_test_tensor.numpy()
mse = mean_squared_error(y_true, y_pred)
print(f'MSE on test set: {mse}')


"""Build a pinecone index with the Development Matters learning goals and examples."""

import os
import uuid

import openai

from dotenv import load_dotenv

from genai.eyfs import get_embedding
from genai.utils import read_json
from genai.vector_index import PineconeIndex

load_dotenv()

openai.api_key = os.environ["OPENAI_API_KEY"]
PATH_TO_DM = "src/genai/dm/dm.json"
INDEX_NAME = "eyfs-index"
ENCODER_NAME = "text-embedding-ada-002"

if "__main__" == __name__:
    data = read_json(PATH_TO_DM)
    # Temp hack to exclude the template
    data = [d for d in data if d["area_of_learning"] != ""]

    # Format the data to what pinecone needs and generate a temp uuid
    docs = []
    for elem in data:
        aol = elem["area_of_learning"]
        d = elem["age_group"]
        for age, age_dict in d.items():
            for k, items in age_dict.items():
                for item in items:
                    doc = tuple(
                        (
                            str(uuid.uuid4()),
                            get_embedding(item),
                            {
                                "age_group": age,
                                "type_": k,
                                "source": "dm",
                                "text": item,
                                "areas_of_learning": aol,
                            },
                        )
                    )
                    docs.append(doc)

    # Build the index
    conn = PineconeIndex(api_key=os.environ["PINECONE_API_KEY"], environment=os.environ["PINECONE_REGION"])

    conn.build_and_upsert(
        index_name=INDEX_NAME,
        dimension=1536,
        metric="euclidean",
        docs=docs,
        metadata_config={"indexed": ["areas_of_learning", "source", "type_", "age_group"]},
        batch_size=40,
    )


# import sys

# M, N = map(int, sys.stdin.readline().split())

# for num in range(M, N + 1):
#     flag = False

#     for i in range(2, num):
#         if num % i == 0:
#             flag = True
#             break

#     if flag == False:
#         print(num)

import sys

def isPrime(start, end):
    sieve = [True] * (end + 1)
    sieve[1] = False

    m = int(end ** 0.5)
    for i in range(2, m + 1):
        if sieve[i] == True:
            for j in range(i + i, end + 1, i):
                sieve[j] = False

    [print(i) for i in range(start, end + 1) if sieve[i] == True]

M, N = map(int, sys.stdin.readline().split())
isPrime(M, N)


import sys
input = sys.stdin.readline

n = int(input())
lst = sorted(list(map(int, input().split())))

m, c = 0, 0
for i in range(n):
    if m < lst[i]*(n-i):
        m = lst[i]*(n-i)
        c = lst[i]

print(m, c)


import hashlib
import os
import mimetypes
import subprocess
import json
import chardet
import warnings
import docx2txt
import xlrd
from pdfminer.pdfparser import PDFParser, PDFSyntaxError
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.layout import LAParams, LTTextBox, LTTextLine
from pdfminer.converter import PDFPageAggregator
import html2text
from ebooklib import epub
import ebooklib
from PIL import Image
from fontTools.ttLib import TTFont, TTLibError
import six
from six.moves import xrange

class MimeGuesser:
    def guess_mime(self, full_path):
        raise NotImplementedError()

class ContentMimeGuesser(MimeGuesser):

    def __init__(self):
        import magic
        self.libmagic = magic.Magic(mime=True)

    def guess_mime(self, full_path):
        try:
            return self.libmagic.from_file(full_path)
        except FileNotFoundError:
            return None

class ExtensionMimeGuesser(MimeGuesser):
    def guess_mime(self, full_path):
        return mimetypes.guess_type(full_path, strict=False)[0]

class FileParser:
    mime_types = []
    is_default = False

    def parse(self, full_path: str):
        raise NotImplemented

class FileCheckSumCalculator:
    def checksum(self, path: str) -> str:
        """
        Calculate the checksum of a file
        :param path: path of the file
        :return: checksum
        """
        raise NotImplementedError()

class Md5CheckSumCalculator(FileCheckSumCalculator):
    def __init__(self):
        self.name = "md5"

    def checksum(self, path: str) -> str:
        """
        Calculate the md5 checksum of a file
        :param path: path of the file
        :return: md5 checksum
        """
        result = hashlib.md5()

        with open(path, "rb") as f:
            for block in iter(lambda: f.read(65536), b""):
                result.update(block)

        return result.hexdigest().upper()

class Sha1CheckSumCalculator(FileCheckSumCalculator):
    def __init__(self):
        self.name = "sha1"

    def checksum(self, path: str) -> str:
        """
        Calculate the sha1 checksum of a file
        :param path: path of the file
        :return: sha1 checksum
        """
        result = hashlib.sha1()

        with open(path, "rb") as f:
            for block in iter(lambda: f.read(65536), b""):
                result.update(block)

        return result.hexdigest().upper()

class Sha256CheckSumCalculator(FileCheckSumCalculator):
    def __init__(self):
        self.name = "sha256"

    def checksum(self, path: str) -> str:
        """
        Calculate the sha256 checksum of a file
        :param path: path of the file
        :return: sha256 checksum
        """
        result = hashlib.sha256()

        with open(path, "rb") as f:
            for block in iter(lambda: f.read(65536), b""):
                result.update(block)

        return result.hexdigest().upper()

class GenericFileParser(FileParser):
    mime_types = []
    is_default = True

    def __init__(self, checksum_calculators: list, root_dir: str):
        self.checksum_calculators = checksum_calculators
        self.root_dir = root_dir
        self.root_dir_len = len(root_dir)+1

    def parse(self, full_path: str) -> dict:
        """
        Parse a generic file
        :param full_path: path of the file to parse
        :return: dict information about the file
        """

        info = dict()

        file_stat = os.stat(full_path)
        path, name = os.path.split(full_path)
        name, extension = os.path.splitext(name)

        info["size"] = file_stat.st_size
        info["path"] = os.path.relpath(path, self.root_dir)
        info["name"] = name
        info["extension"] = extension[1:]
        info["mtime"] = file_stat.st_mtime

        # TODO: calculate all checksums at once
        for calculator in self.checksum_calculators:
            info[calculator.name] = calculator.checksum(full_path)

        return info

class MediaFileParser(GenericFileParser):
    is_default = False
    relevant_properties = ["bit_rate", "nb_streams", "duration", "format_name", "format_long_name"]

    def __init__(self, checksum_calculators: list, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.mime_types = [
            "video/3gpp", "video/mp4", "video/mpeg", "video/ogg", "video/quicktime",
            "video/webm", "video/x-flv", "video/x-mng", "video/x-ms-asf",
            "video/x-ms-wmv", "video/x-msvideo", "audio/basic", "auido/L24",
            "audio/mid", "audio/mpeg", "audio/mp4", "audio/x-aiff",
            "audio/ogg", "audio/vorbis" "audio/x-realaudio", "audio/x-wav",
            "audio/flac", "audio/x-monkeys-audio", "audio/wav", "audio/wave",
            "audio/x-wav", "audio/x-ms-wma", "audio/x-flac",
        ]

    def parse(self, full_path: str):
        info = super().parse(full_path)

        p = subprocess.Popen(["ffprobe", "-v", "quiet", "-print_format", "json=c=1", "-show_format", full_path],
                             stdout=subprocess.PIPE)
        out, err = p.communicate()

        try:
            metadata = json.loads(out.decode("utf-8"))

            if "format" in metadata:

                if "duration" in metadata["format"]:
                    info["duration"] = float(metadata["format"]["duration"])

                if "format_long_name" in metadata["format"]:
                    info["format_long_name"] = metadata["format"]["format_long_name"]

                if "tags" in metadata["format"]:
                    if "genre" in metadata["format"]["tags"]:
                        info["genre"] = metadata["format"]["tags"]["genre"]
                    if "title" in metadata["format"]["tags"]:
                        info["title"] = metadata["format"]["tags"]["title"]
                    if "album" in metadata["format"]["tags"]:
                        info["album"] = metadata["format"]["tags"]["album"]
                    if "album_artist" in metadata["format"]["tags"]:
                        info["album_artist"] = metadata["format"]["tags"]["album_artist"]

        except json.decoder.JSONDecodeError:
            print("json decode error:" + full_path)
            pass

        return info

class PictureFileParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.mime_types = [
            "image/bmp", "image/cgm", "image/cis-cod", "image/g3fax", "image/gif",
            "image/ief", "image/jpeg", "image/ktx", "image/pipeg", "image/pjpeg",
            "image/png", "image/prs.btif", "image/svg+xml", "image/tiff",
            "image/vnd.adobe.photoshop", "image/vnd.dece.graphic", "image/vnd.djvu",
            "image/vnd.dvb.subtitle", "image/vnd.dwg", "image/vnd.dxf",
            "image/vnd.fastbidsheet", "image/vnd.fpx", "image/vnd.fst",
            "image/vnd.fujixerox.edmics-mmr", "image/vnd.fujixerox.edmics-rlc",
            "image/vnd.ms-modi", "image/vnd.net-fpx", "image/vnd.wap.wbmp",
            "image/vnd.xiff", "image/webp", "image/x-citrix-jpeg", "image/x-citrix-png",
            "image/x-cmu-raster", "image/x-cmx", "image/x-icon",
            "image/x-pcx", "image/x-pict", "image/x-png", "image/x-portable-bitmap",
            "image/x-portable-graymap", "image/x-portable-pixmap",
            "image/x-rgb", "image/x-xbitmap", "image/x-xpixmap", "image/x-xwindowdump"
        ]

    def parse(self, full_path: str):

        info = super().parse(full_path)

        try:
            with open(full_path, "rb") as image_file:
                with Image.open(image_file) as image:
                    info["mode"] = image.mode
                    info["format_name"] = image.format
                    info["width"] = image.width
                    info["height"] = image.height
        except (OSError, ValueError):
            pass

        return info

class TextFileParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, content_length: int, root_dir):
        super().__init__(checksum_calculators, root_dir)
        self.content_length = content_length

        self.mime_types = [
            "text/asp", "text/css", "text/ecmascript", "text/html", "text/javascript",
            "text/mcf", "text/pascal", "text/plain", "text/richtext", "text/scriplet",
            "text/sgml", "text/tab-separated-values", "text/uri-list", "text/vnd.abc",
            "text/vnd.fmi.flexstor", "text/vnd.rn-realtext", "text/vnd.wap.wml",
            "text/vnd.wap.wmlscript", "text/webviewhtml", "text/x-asm", "text/x-audiosoft-intra",
            "text/x-c", "text/x-component", "text/x-fortran", "text/x-h", "text/x-java-source",
            "text/x-la-asf", "text/x-m", "text/x-pascal", "text/x-script",
            "text/x-script.csh", "text/x-script.elisp", "text/x-script.guile",
            "text/x-script.ksh", "text/x-script.lisp", "text/x-script.perl",
            "text/x-script.perl-module", "text/x-script.phyton", "text/x-script.rexx",
            "text/x-script.scheme", "text/x-script.sh", "text/x-script.tcl",
            "text/x-script.tcsh", "text/x-script.zsh", "text/x-server-parsed-html",
            "text/x-setext", "text/x-sgml", "text/x-speech", "text/x-uil",
            "text/x-uuencode", "text/x-vcalendar", "text/xml", "text/x-csrc", "text/csv",
            "text/x-c++src", "text/x-chdr", "text/markdown", "text/x-sh", "text/x-java",
            "text/x-python", "text/x-c++hdr", "text/x-tex", "text/x-diff", "text/x-haskell",
            "text/x-perl", "text/x-dsrc", "text/scriptlet", "text/x-scala", "text/calendar",
            "text/x-bibtex", "text/x-tcl", "text/x-c++", "text/x-shellscript", "text/x-msdos-batch",
            "text/x-makefile", "text/rtf", "text/x-objective-c", "text/troff", "text/x-m4",
            "text/x-lisp", "text/x-php", "text/x-gawk", "text/x-awk", "text/x-ruby", "text/x-po",
            "text/x-makefile", "application/javascript", "application/rtf", "application/json",
        ]

    def parse(self, full_path: str):
        info = super().parse(full_path)

        if self.content_length > 0:
            with open(full_path, "rb") as text_file:
                raw_content = text_file.read(self.content_length)

                chardet.detect(raw_content)
                encoding = chardet.detect(raw_content)["encoding"]

                if encoding is not None:
                    info["encoding"] = encoding
                    try:
                        content = raw_content.decode(encoding, "ignore")
                        info["content"] = content
                    except Exception:
                        print("Unknown encoding: " + encoding)

        return info

class FontParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.mime_types = [
            "application/font-sfnt", "application/font-woff", "application/vdn.ms-fontobject",
            "application/x-font-ttf"
        ]

    def parse(self, full_path: str):

        info = super().parse(full_path)

        with open(full_path, "rb") as f:

            with warnings.catch_warnings():
                warnings.simplefilter("ignore")

                try:
                    font = TTFont(f)

                    if "name" in font:
                        try:
                            for name in font["name"].names:
                                if name.nameID == 4:
                                    info["content"] = name.toUnicode("replace")
                                    break
                        except AssertionError:
                            print("Could not read font name for " + full_path)
                except TTLibError:
                    print("Could not read font for " + full_path)

        return info

class PdfFileParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, content_length: int, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.content_length = content_length

        self.mime_types = [
            "application/pdf", "application/x-pdf"
        ]

    def parse(self, full_path: str):
        info = super().parse(full_path)

        if self.content_length > 0:
            with open(full_path, "rb") as f:

                try:
                    parser = PDFParser(f)
                    document = PDFDocument(parser)
                except PDFSyntaxError:
                    print("couldn't parse PDF " + full_path)
                    return info

                info["content"] = ""
                if len(document.info) > 0 and "Title" in document.info[0] and document.info[0]["Title"] != b"":
                    if isinstance(document.info[0]["Title"], bytes):
                        info["content"] += document.info[0]["Title"].decode("utf-8", "replace") + "\n"
                    else:
                        info["content"] += document.info[0]["Title"].resolve().decode("utf-8", "replace") + "\n"

                try:
                    if document.is_extractable:
                        resource_manager = PDFResourceManager()
                        la_params = LAParams()

                        device = PDFPageAggregator(resource_manager, laparams=la_params)
                        interpreter = PDFPageInterpreter(resource_manager, device)

                        for page in PDFPage.create_pages(document):

                            interpreter.process_page(page)
                            layout = device.get_result()

                            for lt_obj in layout:
                                if isinstance(lt_obj, LTTextBox) or isinstance(lt_obj, LTTextLine):

                                    text = lt_obj.get_text()

                                    if len(info["content"]) + len(text) <= self.content_length:
                                        info["content"] += text
                                    else:
                                        info["content"] += text[0:self.content_length - len(info["content"])]
                                        break
                            else:
                                continue
                            break
                    else:
                        print("PDF is not extractable: " + full_path)
                except ValueError:
                    print("Couldn't parse page for " + full_path)

        return info

class EbookParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, content_length: int, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.content_length = content_length

        self.mime_types = [
            "application/epub+zip"
        ]

        self.html2text = html2text.HTML2Text()
        self.html2text.ignore_images = True
        self.html2text.ignore_emphasis = True

    def parse(self, full_path: str):
        info = super().parse(full_path)

        book = epub.read_epub(full_path)

        info["content"] = ""

        for text in book.get_items_of_type(ebooklib.ITEM_DOCUMENT):

            text = self.html2text.handle(text.content.decode("utf-8"))

            if len(info["content"]) + len(text) <= self.content_length:
                info["content"] += text
            else:
                info["content"] += text[0:self.content_length - len(info["content"])]
                break

        return info

class DocxParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, content_length: int, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.content_length = content_length

        self.mime_types = [
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
        ]

    def parse(self, full_path: str):
        info = super().parse(full_path)

        if self.content_length > 0:
            try:
                text = docx2txt.process(full_path)

                if len(text) < self.content_length:
                    info["content"] = text
                else:
                    info["content"] = text[0:self.content_length]
            except:
                print("Couldn't parse Ebook: " + full_path)

        return info

class SpreadSheetParser(GenericFileParser):
    is_default = False

    def __init__(self, checksum_calculators: list, content_length: int, root_dir):
        super().__init__(checksum_calculators, root_dir)

        self.content_length = content_length

        self.mime_types = [
            "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        ]

    def parse(self, full_path: str):
        info = super().parse(full_path)

        # The MIT License (MIT)
        # Copyright (c) 2014 Dean Malmgren
        # https://github.com/deanmalmgren/textract/blob/master/textract/parsers/xlsx_parser.py

        try:
            workbook = xlrd.open_workbook(full_path)

            sheets_name = workbook.sheet_names()
            info["content"] = ""

            for names in sheets_name:
                worksheet = workbook.sheet_by_name(names)
                num_rows = worksheet.nrows
                num_cells = worksheet.ncols

                for curr_row in range(num_rows):
                    new_output = []
                    for index_col in xrange(num_cells):
                        value = worksheet.cell_value(curr_row, index_col)
                        if value:
                            if isinstance(value, (int, float)):
                                value = six.text_type(value)
                            new_output.append(value)

                    if new_output:
                        text = u' '.join(new_output) + u'\n'
                        if len(info["content"]) + len(text) <= self.content_length:
                            info["content"] += text
                        else:
                            info["content"] += text[0:self.content_length - len(info["content"])]
                            break

            return info

        except xlrd.biffh.XLRDError:
            print("Couldn't parse spreadsheet: " + full_path)


from .models import *
from faker import Faker
fake = Faker()
import random
choice=['math','science','english','hindi','histrory']
def seed_subdb(n):
    for i in range(0 , n):
        Subject.objects.create(
            subName = choice[i],
        )
lastname=['kumar','singh','paswaan']
def seed_prodb(n):
    for x in range(0,n):
         Professor.objects.create(
             p_fname=fake.name(),
             p_lname=lastname[random.lastname(0,3)],
             subjects=choice[random.randint(0,4)]
         )


from eval_utils import process_results, load_score_t5
from multitask_info import target2source_taskweb, target2source_mix1, target2source_mix2, target2source_mix3, target2source_mix4, target2source_mix5

if __name__ == "__main__":

    # list of all target tasks and random seeds
    task_list = ["anli_r3", "copa", "hellaswag", "rte"]
    seed_list = [15, 30, 42]

    # T5-3B zero-shot evaluation results with TaskWeb (top-5)
    process_results(task_list, load_score_t5, multitask_dict=target2source_taskweb, result_name="T5-XL original", seed_list=seed_list)

    # T5-3B zero-shot evaluation results with 1 unhelpful source task mixed
    process_results(task_list, load_score_t5, multitask_dict=target2source_mix1, result_name="T5-XL mix-1", seed_list=seed_list)

    # T5-3B zero-shot evaluation results with 2 unhelpful source tasks mixed
    process_results(task_list, load_score_t5, multitask_dict=target2source_mix2, result_name="T5-XL mix-2", seed_list=seed_list)

    # T5-3B zero-shot evaluation results with 3 unhelpful source tasks mixed
    process_results(task_list, load_score_t5, multitask_dict=target2source_mix3, result_name="T5-XL mix-3", seed_list=seed_list)

    # T5-3B zero-shot evaluation results with 4 unhelpful source tasks mixed
    process_results(task_list, load_score_t5, multitask_dict=target2source_mix4, result_name="T5-XL mix-4", seed_list=seed_list)

    # T5-3B zero-shot evaluation results with 5 unhelpful source tasks mixed
    process_results(task_list, load_score_t5, multitask_dict=target2source_mix5, result_name="T5-XL mix-5", seed_list=seed_list)