# A couple of abstract classes that contain commonly used fields
from django.db import models

from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, \
    InlinePanel, PageChooserPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailimages.models import Image
from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel
from wagtail.wagtailsnippets.models import register_snippet
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
from wagtail.wagtailsearch import index

class LinkFields(models.Model):

    class Meta:
        abstract = True

    link_external = models.URLField("External link", blank=True)
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+'
    )
    link_document = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        related_name='+'
    )

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        elif self.link_document:
            return self.link_document.url
        else:
            return self.link_external

    panels = [
        FieldPanel('link_external'),
        PageChooserPanel('link_page'),
        DocumentChooserPanel('link_document'),
    ]

class RelatedLink(LinkFields):

    class Meta:
        abstract = True

    title = models.CharField(max_length=255, help_text="Link title")

    panels = [
        FieldPanel('title'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

class CarouselItem(LinkFields):

    class Meta:
        abstract = True

    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    embed_url = models.URLField("Embed URL", blank=True)
    caption = models.CharField(max_length=255, blank=True)

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('embed_url'),
        FieldPanel('caption'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]


from xai.brain.wordbase.nouns._lunatic import _LUNATIC

#calss header
class _LUNATICS(_LUNATIC, ):
	def __init__(self,):
		_LUNATIC.__init__(self)
		self.name = "LUNATICS"
		self.specie = 'nouns'
		self.basic = "lunatic"
		self.jsondata = {}


# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import time
import base64
from openerp import pooler
from openerp.osv import osv
from openerp.report import report_sxw
from openerp.tools.translate import _

class mrp_planning_bom(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(mrp_planning_bom, self).__init__(cr, uid, name, context=context)
        self.pricelist=False
        self.quantity=[]
        self.localcontext.update({
            'time': time,
            'get_period': self._get_period,
            'get_boms': self._get_boms,
            'get_titles': self._get_titles,
        })

    def _get_titles(self, form):

        lst = [{'qty': 'BoMs sum'}]
        return lst

    def _get_period(self, form):
        period = str(form['year']+'/'+form['month'])
        return period

    def _get_boms(self, form):

        pool = pooler.get_pool(self.cr.dbname)
        planning = pool.get('mrp.planning.report')
        product = planning.browse(self.cr, self.uid, form['id'], context=None)
        res = []
        count = 1
        for bom_id in product.boms:
            bom = {}
            bom['product'] = bom_id.product_id.name
            bom['qty'] = bom_id.qty
            bom['count'] = count
            res.append(bom)
            count += 1
        return res

report_sxw.report_sxw('report.mrp.planning.bom','mrp.planning.report','addons/mrp_planning_report/report/mrp_planning_bom.rml',parser=mrp_planning_bom)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:


#!/bin/env python
# coding:utf-8
import sqlite3
import MeCab
import argparse
# ネガポジ辞書作成
import urllib.request
#from mpi4py import MPI
import pandas as pd
import codecs
import logging
import json
import numpy as np
logger = logging.getLogger("logger")    #logger名loggerを取得
logger.setLevel(logging.DEBUG)  #loggerとしてはDEBUGで

def get_emoji():
    with open("../notebook/emoji_sentiment.json","r") as f:
        emoji = json.load(f)
    return emoji

def main():
    parser = argparse.ArgumentParser(description='calculate board score')
    parser.add_argument('--db',type=str, default="/Volumes/DATA/data/board/board.db")
    parser.add_argument('--dump',type=str, default="board_emoji_score.dump")
    parser.add_argument('--logfile',type=str, default="02_emoji_score.log")
    parser.add_argument('--fmdate',type=str,default="2017-05-01")
    parser.add_argument('--todate',type=str,default="2017-05-31")
    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG,
                        filename=args.logfile,
                        format="%(asctime)s %(levelname)-7s %(message)s")

    emoji=get_emoji()

    tagger = MeCab.Tagger('-Ochasen')
    # http://qiita.com/kasajei/items/0805b433f363f1dba785
    tagger.parse("")
    # 文をMecabで単語分割
    def mecab_analysis(sentence):
        res=[]
        s = sentence.replace('\n', ' ')
        node = tagger.parseToNode(s)
        while node:
            if node.surface != "":  # BOS/EOSを除外
                ftlist = (node.feature).split(',')
                if ftlist[6] != "*":
                    o = ftlist[6]
                else:
                    o = node.surface
                res.append(o+"\t"+ftlist[0])  # word \t hinshi
            node = node.next
        return res

    def negaposi_score(word_list,dict):
        scores=[]
        score=0
        neg=0
        pos=0
        neu=0
        emojinum=0
        for wd in word_list:
            (word,hinshi)=wd.split("\t")
            if word in dict:
               lst=dict[word]
               neg=neg+lst[0]
               neu=neu+lst[1]
               pos=pos+lst[2]
               score=score+lst[3]
               emojinum+=1
               scores.append(lst[3])

        score_std=np.std(np.array(scores))
        return (len(word_list),emojinum,score,neg,neu,pos,score_std)

    con=sqlite3.connect(args.db)
    import pandas as pd
    cur = con.cursor()
    data = pd.io.sql.read_sql_query("select * from board where date between '" + args.fmdate + "' and '" + args.todate + "'", con)
    cur.close()
    con.close()

    mcon=sqlite3.connect(":memory:")
    mcur = mcon.cursor()
    with open("board.sql", "r") as f:
        lines = "".join(f.readlines())
        for sql in lines.split(";"):
            mcur.execute(sql)
            mcon.commit()

    for code, tno, mno, body in zip(data["code"], data["tno"], data["mno"], data["body"]):
        (sentence_wordnum,emoji_num, score,neg,neu,pos,score_std) = negaposi_score(mecab_analysis(body), emoji)
        if(score==0 and neg==0 and neu==0 and pos==0):
            continue
        mcur.execute("insert into board_emoji_sentiment_score values (?,?,?,?,?,?,?,?,?,?)",(code,str(tno),str(mno),score,score_std,neg,neu,pos,emoji_num,sentence_wordnum,))
        print(str(code)+","+str(tno)+","+str(mno)+","+str(score)+","+str(emoji_num)+","+str(sentence_wordnum))

    mcon.commit()

    with open(args.dump, 'w') as f:
        for line in mcon.iterdump():
            f.write('%s\n' % line)

if __name__ == "__main__":
    main()


def floatInput(text, empty = False, type = float, min = None, max = None, errorMess = "Invalid input, try again.", AZ = "", noDubs = False):
	AtoZ = ""
	if AZ != "":
		if AZ.find("l") >= 0:
			AtoZ = AtoZ + "abcdefghijklmnopqrstuvwxyz"
		if AZ.find("u") >= 0:
			AtoZ = AtoZ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	while True:
		leInput = input(text)
		if noDubs:
			leInputClone = list(leInput)
			for i in range(len(leInputClone)):
				if i > len(leInput):
						pass
				else:
					tempValueHolder = leInputClone.pop(0)
					if tempValueHolder in leInputClone:
						print(errorMess)
						break
					elif i == len(leInput) - 1:
						if AZ != None and type == str:
							returnVar = (AZCheck(leInput, errorMess, AtoZ, min, max))
						elif type == int or type == float:
							returnVar = typeCheck(leInput, errorMess, min, max, type)
						if returnVar != None:
							return(returnVar)
						else:
							print(errorMess)
			continue
		if empty and leInput == "":
			return(leInput)
		if AZ != None and type == str:
			returnVar = (AZCheck(leInput, errorMess, AtoZ, min, max))
		elif type == int or type == float:
			returnVar = typeCheck(leInput, errorMess, min, max, type)
		if returnVar != None:
			return(returnVar)

def  typeCheck(leInput, errorMess, min, max, type):
	try:
		if min == None and max == None:
			return(type(leInput))
		else:
			type(leInput)
	except ValueError:
		return(None)
	try:
		if type(leInput) >= min and type(leInput) <= max:
			return(type(leInput))
		else:
			return(None)
	except TypeError:
		return(None)

def AZCheck(leInput, errorMess, AtoZ, min, max):
	checkForAZ = 0
	for i in range(len(leInput)):
		if not leInput[i] in AtoZ:
			checkForAZ += 1
	if checkForAZ == 0 and min == None and max == None:
		return(leInput)
	elif checkForAZ == 0 and len(leInput) >= min and len(leInput) <= max:
		return(leInput)
	else:
		print(errorMess)


# Import necessary entities
from datadog import initialize, api

options = {
    # Find your keys here:
    # https://app.datadoghq.com/account/settings#api
    'api_key': '****************************************',
    'app_key': '****************************************'
}

initialize(**options)

# Title displayed on the top of the Timeboard
title = "Logfathers Timemachine"

# Let everyone know your intentions as to what this timeboard was created for.
description = "This timeboard presents everything that is necessary to become a successful sales engineer for Datadog. Arf."

graphs = [{
    "definition": {
        "events": [],
        "requests": [
            {"q": "avg:logfather_cpu{*}"},
            {"q": "avg:logfather_cpu{*}.rollup(sum, 60)" }
        ],
        "viz": "timeseries"
    },
    "title": "CPU usage scoped over the host Logfather"
},

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "anomalies(avg:logfather_cpu{*}, 'basic', 2)"}
        ],
        "viz": "timeseries"
    },
    "title": "# of CPU Anomalies"
}]

template_variables = [{
    "name": "Logfathers Timemachine", # REQUIRED. The name of the variable
    "prefix": "", #OPTIONAL. The tag prefix associated with the variable. Only tags with this prefix appear in the variable dropdown.
    "default": "" # OPTIONAL. The default value for the template variable on dashboard load.
}]

read_only = True # Make sure nobody can manipulate your timeboard

api.Timeboard.create(title=title,
                     description=description,
                     graphs=graphs,
                     template_variables=template_variables,
                     read_only=read_only)


import requests
from bs4 import BeautifulSoup

'''
Ethan Gilmore
November 26, 2018

simple web scraper script i made whenever i can only remember a part of a teachers name and need to get their email
'''

def findEmail(name):
    url = "http://www.pineview.org/faculty/"
    Request = requests.get(url) #get html
    TeacherData = BeautifulSoup(Request.text, 'html.parser') #beautify it???

    emails = TeacherData.findAll("p") #find all the p tags which were the emails
    possibleEmails = []
    finalEmails = []
    for email in emails:
        emailText = email.getText()
        if(emailText.find(name) != -1 and emailText.find("@") != -1): #if input is in email and this comparison is against an actual email
            possibleEmails.append(emailText) #add it to the list

    for email in possibleEmails: #i think this is just all fixing up the emails a little bit
        emailCutoff = email.find(".org")
        newEmail = email[0:(emailCutoff)+4]
        finalEmails.append(newEmail) #add prettified emails to new list

    return finalEmails #return list of possible emails

if __name__ == "__main__":
    teacherName = input()
    print(findEmail(teacherName))


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''

A command line utility for the Pydlock package.

Software:      Pydlock
Author:        Erick Edward Shepherd
E-mail:        Contact@ErickShepherd.com
GitHub:        https://www.github.com/ErickShepherd/pydlock
PyPI:          https://pypi.org/project/pydlock/
Date created:  2020-04-30
Last modified: 2020-04-30

Description:

    A command line utility for the Pydlock package, which allows users to lock
    and unlock files with a password, or run Python scripts locked by Pydlock.

Usage:

    This module may be executed from the command line as a Python script:

        python -m pydlock

    Running the script without any arguments will display the usage:

        usage: pydlock.py [-h] [--arguments ARGUMENTS] [--encoding ENCODING]
                          {lock,unlock,python,run} file

    Supported operations include:

        lock:   Encrypts a file in-place.
        unlock: Decrypts a file in-place.
        python: Decrypts and runs the contents of a Python file.
        run:    Temporarily decrypts, runs, and re-encrypts an arbitrary file.

    Example:

        python -m pydlock lock example.txt --encoding=utf-8

Copyright:

    Pydlock - A Python file encryption tool.

    Copyright (c) 2020 of Erick Edward Shepherd, all rights reserved.

License:

    This file is part of "Pydlock" (the "Software").

    MIT License

    Copyright (c) 2020 Erick Edward Shepherd

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the right to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.

Notes:

    Issues with use on Windows executables:

        Because the files are modified, locking and unlocking executables on
        Windows does not preserve their checksum. Consequently, after locking
        and unlocking an executable on Windows, when an execution is attempted,
        the system raises an error for security purposes:

            "This version of <file> is not compatible with the version of
            Windows you're running. Check your computer's system information
            and then contact the software publisher."

        There does not appear to be a simple resolution for this issue, and the
        files effectively become corrupted.

'''

# Standard library imports.
import os
from argparse import ArgumentParser

# Local application imports.
import pydlock
from pydlock.constants import DEFAULT_ENCODING

# Dunder definitions.
__author__  = pydlock.__author__
__version__ = pydlock.__version__

if __name__ == "__main__":

    # Maps function names to the respective function.
    function_map = {
        "lock"    : pydlock.lock,
        "unlock"  : pydlock.unlock,
        "python"  : pydlock.python,
        "run"     : pydlock.run
    }

    # Parses command-line arguments from the user.
    parser = ArgumentParser()
    parser.add_argument("operation",   choices = function_map.keys())
    parser.add_argument("file",        type = os.path.abspath)
    parser.add_argument("--arguments", type = str, default = "")
    parser.add_argument("--encoding",  type = str, default = DEFAULT_ENCODING)
    kwargv = vars(parser.parse_args())

    # Aliases parsed command-line arguments for brevity.
    task      = function_map[kwargv["operation"]]
    path      = kwargv["file"]
    arguments = kwargv["arguments"]
    encoding  = kwargv["encoding"]

    # Performs the indicated task.
    task(path, arguments, encoding)


# Returns if the passed string is a valid integer
def IsValidInteger(Input):
    # If it can be parsed to an integer it is valid, else it is not
    try:
        int(Input)
        return True
    except ValueError:
        return False

# Get a valid integer input from the user
def InputInteger(Message):
    Input = input(Message)

    # Repeatedly get a new input until a valid integer is input
    while not IsValidInteger(Input):
        Input = input("Invalid input. " + Message)

    # Return the integer
    return int(Input)

# A class that stores information about a story, including the author, title, and word count
class ShortStory:
    def __init__(self, StoryInformation):
        self.Story = StoryInformation[0]
        self.Author = StoryInformation[1]
        self.WordCount = len(StoryInformation[0].split(" "))

# The class which controls all of the interaction with the user
class ShortStoryExplorer:
    # Initialize the class, map the passed array to short story objects
    def __init__(self, Stories):
        self.Stories = list(map(lambda Story: ShortStory(Story), Stories))

    # Display the help menu
    def DisplayMenu(self):
        print("*** Short Story Explorer ***\n   d - Display all short stories\n   a - Display all stories with a specified author\n   wc - Display all short stories with less than the specified amount of words\n   aw - Display all stories by the specified author which contain the specfied word\n   q - Quit\n   h - Display this menu")

    # Returns whether the passed value is a valid command
    def IsValidCommand(self, Command):
        return Command in ["d", "a", "aw", "wc", "h"]

    # Executes a command
    def ExecuteCommand(self, Command):
        {
            "d": self.DisplayAll,
            "a": self.FindWithAuthor,
            "aw": self.FindWithAuthorAndWord,
            "wc": self.FindWithMaxWords,
            "h": self.DisplayMenu
        }[Command]()

    # Display all short stories
    def DisplayAll(self):
        self.DisplayStories(self.Stories)

    # Display all short stories for which the authors name contains the entered string
    def FindWithAuthor(self):
        Author = input("Enter the author for which you would like to find stories from: ")

        self.DisplayStories(list(filter(lambda Story: Author.lower() in Story.Author.lower(), self.Stories)))

    # Display all stories by the specfied author which contains the specified word
    def FindWithAuthorAndWord(self):
        Author = input("Enter the author for which you would like to find stories from: ").lower()
        Word = input("Enter the word which should be present in the story: ").lower()

        self.DisplayStories(list(filter(lambda Story: Author in Story.Author.lower() and Word in Story.Story.lower(), self.Stories)))

    # Display all stories which have at most the specified amount of words
    def FindWithMaxWords(self):
        MaxWords = InputInteger("Enter the amount of words for which all stories less than should be found: ")

        SearchResults = list(filter(lambda Story: Story.WordCount < MaxWords, self.Stories))

        if len(SearchResults) == 0:
            print("No stories with less than or equal to %d words could be found" % (MaxWords))
        else:
            self.DisplayStories(SearchResults)

    # Display the passed stories to the user, used by all search methods
    def DisplayStories(self, Stories):
        for Story in Stories:
            print("-- %s --" % (Story.Author))

            for Line in Story.Story.split("\n"):
                print("    %s" % (Line))

            print("\n")

# Intialize the short story explorer
StoryExplorer = ShortStoryExplorer([
    ['With bloody hands, I say good-bye.', 'Frank Miller'],
    ['TIME MACHINE REACHES FUTURE!!! ... nobody there ...', 'Harry Harrison'],
    ['The baby\'s blood type? Human, mostly.', 'Orson Scott Card'],
    ['For sale: baby shoes, never worn.', 'Ernest Hemingway'],
    ['Corpse parts missing. Doctor buys yacht.', 'Margaret Atwood'],
    ['We kissed. She melted. Mop please!', 'James Patrick Kelly'],
    ['Starlet sex scandal. Giant squid involved.', 'Margaret Atwood'],
    ['Will this do (lazy writer asked)?', 'Ken McLeod'],
    ["I'm sorry, but there's not enough air in here for everyone. I’ll tell them you were a hero.", 'J. Matthew Zoss'],
    ['Waking Up To Silence: Deafening silence. I strain my ears, praying there might be someone else still alive. The only noise I hear are the voices in my head', 'Mike Jackson'],
    ["Not In My Job Description: Make sure it's done by the end of the day Jones.\nBut, sir, it's not in my ....\nJust do it, and remember, no blood.", 'Mike Jackson'],
    ['Empty Baggage: The trunk arrived two days later. He lifted the lid and froze, it was empty. No arms, no legs, no head, nothing. Where was she?', 'Mike Jackson'],
    ['Forgot My Own Name: The hospital said it was concussion.\nMight be permanent memory loss.\nCan\'t even remember my own name - which is handy considering who I am.', 'Mike Jackson']
])

# Display the menu
StoryExplorer.DisplayMenu()

# Get the command that should be executed
CommandToExecute = input("> ")

# Go into an infinite loop getting and executing commands until the "q" command is given
while(CommandToExecute != "q"):
    # If the command is valid execute it
    if StoryExplorer.IsValidCommand(CommandToExecute):
        StoryExplorer.ExecuteCommand(CommandToExecute)

    # Get the next command to execute
    CommandToExecute = input("> ")


#!/usr/bin/env python3
#

import asyncio
import time

'''
uture对象有几个状态：

- Pending： 创建future，还未执行
- Running： 事件循环正在调用执行任务
- Done： 任务执行完毕
- Cancelled： Task被取消后的状态

创建future的时候，task为pending，
事件循环调用执行的时候当然就是running，
调用完毕自然就是done，
如果需要停止事件循环，就需要先把task取消。
可以使用asyncio.Task获取事件循环的task
'''

now = lambda: time.time()

async def do_some_work(x):
    print("Waiting:", x)
    await asyncio.sleep(x)
    return "Done after {}s".format(x)

async def main():
    coroutine10 = do_some_work(10)
    coroutine5 = do_some_work(5)
    coroutine3 = do_some_work(3)
    coroutine1 = do_some_work(1)

    tasks = [
        asyncio.ensure_future(coroutine10),
        asyncio.ensure_future(coroutine5),
        asyncio.ensure_future(coroutine3),
        asyncio.ensure_future(coroutine1)
    ]
    return await asyncio.gather(*tasks)

if __name__ == '__main__':

    start = now()

    loop = asyncio.get_event_loop()

    # 启动事件循环之后，马上ctrl+c，会触发 run_until_complete 的执行异常 KeyBorardInterrupt。然后通过循环 asyncio.Task 取消 future
    try:
        # main() 相当于一个打包好的 asyncio.wait(tasks) 或者 asyncio.gather(*tasks)
        loop.run_until_complete(main())
    except KeyboardInterrupt as e:
        # print(asyncio.Task.all_tasks())
        [print(task) for task in asyncio.Task.all_tasks()]
        # True表示cannel成功，loop stop之后还需要再次开启事件循环，最后在close，不然还会抛出异常

        # True表示cannel成功，loop stop之后还需要再次开启事件循环，最后再close，不然还会抛出异常：
        # [print(task.cancel()) for task in asyncio.Task.all_tasks()]
        print(asyncio.gather(*asyncio.Task.all_tasks()).cancel())
        loop.stop()
        loop.run_forever()
    finally:

        loop.close()

    print('time: ', now() - start)


import pandas as pd
import numpy as np
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.decomposition import PCA

class Preprocessing:
    """
    Preprocessing utility fonction
    """

    def get_onehot_data(self, dataset):
        onehot_data = OneHotEncoder(dtype=int).fit_transform(
            dataset[['state', 'country', 'industry', 'sector']])

        onehot_data = pd.DataFrame(onehot_data.A)

        return onehot_data

    def get_var_data(self, dataset):
        var0 = dataset["Close0"] / dataset["Open0"] - \
            np.ones(dataset["Close0"].shape[0])

        var1 = dataset["Close1"] / dataset["Open1"] - \
            np.ones(dataset["Close1"].shape[0])

        var_height_low = dataset["High0"] / dataset["Low0"] - \
            np.ones(dataset["High0"].shape[0])

        return pd.DataFrame({"var0": var0, "var1": var1, "var_height_low": var_height_low})

    def get_normalized_volume(self, dataset):
        normalized_volume = (
            dataset["Volume0"] - dataset["Volume0"].mean()) / np.sqrt(dataset["Volume0"].var())

        normalized_volume = pd.DataFrame(
            {"normalized_volume": normalized_volume})

        return normalized_volume

    def get_normalized_date(self, dataset):
        normalized_day = dataset["day"] / 31
        normalized_month = dataset["month"] / 12

        return pd.DataFrame({"normalized_day": normalized_day, "normalized_month": normalized_month})

class Preprocessing1(Preprocessing):
    def get(self, dataset):
        """
        Preprocessing pipeline
        """

        print("Cleaning...")
        dataset = dataset.dropna(subset=['Open0', 'High0', 'Low0', 'Close0',
                                         'Volume0', 'Open1', 'Close1']).reset_index().drop_duplicates()

        index = dataset[["symbol", "longName"]]

        print("Refactoring...")
        onehot_data = self.get_onehot_data(dataset)
        var_data = self.get_var_data(dataset)
        normalized_volume = self.get_normalized_volume(dataset)
        normalized_date = self.get_normalized_date(dataset)

        dataset = onehot_data.join(var_data).join(
            normalized_volume).join(normalized_date)

        Y = dataset["var1"]

        print("PCA...")
        pca = PCA(n_components=80)
        X = pca.fit_transform(dataset.drop(columns="var1"))

        print("standardize...")
        standardizer = StandardScaler()
        X = standardizer.fit_transform(X)

        X = pd.DataFrame(X)

        return index, X, Y

def main():
    dataset = pd.read_csv("dataset.csv", sep=";")
    index, X, Y = Preprocessing1().get(dataset)

    print(index.head())
    print(Y.head(5))
    print(X.head(5))

if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
"""
Created on Thu Jun  6 16:00:35 2019

@author: Richard
"""

import numpy as np
import matplotlib.pyplot as plt
import os
import sys
sys.path.append("C:/Users/Richard/Dropbox/Venezuela/data/cleandata")
sys.path.append("C:/Users/Richard/Dropbox/Venezuela/data/rawdata/usindustries")
sys.path.append("C:/Users/Richard/Dropbox/Venezuela/data/rawdata/codes")
sys.path.append("C:/Users/Richard/Dropbox/Venezuela/code/python/production")
sys.path.append("C:/Users/Richard/Dropbox/Venezuela/code/python/clean")
root = 'C:/Users/Richard/Dropbox/Venezuela/'
inddir = 'data/rawdata/usindustries/'
codedir = 'data/rawdata/codes/'
import load_venezuela as v
import prod_venezuela as prod
import pandas as pd
# import tfp_venezuela as tfp
import seaborn as sns
#import ven_graphs as gr
hfont = {'fontname': 'Palatino Linotype'}

# Import production estimates
#filehandler = open('../pf_estimates/acf_estimates.pkl', 'rb')
#industries = pickle.load(filehandler)
industries = []
for i, sic in enumerate(v.industries):
    print(str(i) + ' -- ' + v.inddesc[sic])
    industries += [prod.industry(v.ven_data.loc[v.ven_data['sic'] == sic],
                                 sic)]

# Load US Sector Shares
us_naics = pd.read_csv(root + inddir + "naics5811.csv")

us_naics['wl'] = us_naics['pay']
us_naics['l_share'] = us_naics['wl'] / (us_naics['wl']
                                        + 0.1 * us_naics['cap']
                                        * us_naics['piinv'])

isic31_naics = pd.read_csv(root + codedir + '2002_NAICS_to_ISIC_3.1.csv')
isic2_isic31 = pd.read_csv(root + codedir + 'isic2_isic31.txt')
isic31_naics['isic31'] = isic31_naics['isic31'].astype(str)

def isic2_to_naics(isic2):
    isic31 = isic2_isic31.loc[isic2_isic31['Rev2'] == int(isic2),
                              'Rev31'].values
    naics = []
    for i in isic31:
        if sum(isic31_naics['isic31'] == str(int(i))) > 0:
            naics += list(isic31_naics.loc[isic31_naics['isic31'] == str(int(i)),
                                           'naics'].values)
    return naics

for ind in industries:
    print(ind.sic)
    ls=np.mean(us_naics.loc[(us_naics['naics'].isin(isic2_to_naics(ind.sic)))
                            & (us_naics['year'] == 1976), 'l_share'])
    ind.add_usShare([1-ls, ls])


import glob
import json
from invoke import task

from .vars import package_name, doc_notebooks_dir

@task
def test(c, option="", html=False, xml=False, notebook_tests=True):

    comm = "python -m pytest --cov={}".format(package_name)
    if option:
        comm += " --{}".format(option)
    if html:
        comm += " --cov-report=html"
    elif xml:
        comm += " --cov-report=xml:{}/coverage.xml".format(package_name)

    if notebook_tests:
        new_test_scripts = []
        for nb_idx, nb_file in enumerate(
            glob.glob("{}/*.ipynb".format(doc_notebooks_dir))
        ):
            nb_dic = json.load(open(nb_file))
            nb_code = "\n".join(
                [
                    "\n".join(c["source"])
                    for c in nb_dic["cells"]
                    if (c["cell_type"] == "code")
                ]
            )
            if len(nb_code) > 0:
                new_test_scripts.append(
                    "def test_nb_integration_{}():\n".format(nb_idx)
                    + "\n".join(
                        ["    {}".format(s) for s in nb_code.split("\n")]
                    )
                )
        with open(
            "{}/tests/test_nb_integrations.py".format(package_name), "w"
        ) as fp:
            fp.write("\n\n".join(new_test_scripts))

    c.run(comm)
    c.run("rm {}/tests/test_nb_integrations.py".format(package_name))


#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/8/1 8:16 AM
# @Author  : zhongch4g
# @Site    :
# @File    : 647. Find All Anagrams in a String.py
# @Software: IntelliJ IDEA

class Solution:
    """
    @param s: a string
    @param p: a string
    @return: a list of index
    """
    def findAnagrams(self, s, p):
        lens = len(s)
        lenp = len(p)
        st = [0] * 30
        for c in p:
            st[ord(c) - ord('a')] += 1
        res = []
        start, end, matched = 0, 0, 0
        while end < lens:
            if st[ord(s[end]) - ord('a')] >= 1:
                matched += 1
            st[ord(s[end]) - ord('a')] -= 1

            if matched == lenp:
                res.append(start)

            end += 1

            if end - start == len(p):
                if st[ord(s[start]) - ord('a')] >= 0:
                    matched -= 1
                st[ord(s[start]) - ord('a')] += 1

                start += 1
        return res

s = "cbaebabacd"
p = "abc"
solution = Solution()
res = solution.findAnagrams(s, p)
print(res)

Lintcode/647. Find All Anagrams in a String.py


import csv

# id,name,country_id,year_began,year_ended,notes,url

rf = open('publisher.csv', 'r')
wf = open('publisher_new.csv', 'w')

def clean(string):
    return string.strip().replace('NULL', '')

reader = csv.reader(rf, delimiter=',')
next(reader, None)

writer = csv.writer(wf)
for row in reader:
    writer.writerow((

        clean(row[0]),
        clean(row[1]),
        clean(row[2]),
        clean(row[3]),
        clean(row[4]),
        clean(row[5]),
        clean(row[6])

    ))


#!/usr/bin/env python3
# -*- coding = utf-8 -*-
'''
 @Author : RuiJia Li
 @Time   : 2022/5/2 0:42
 @File   : 四数之和
 @Desc   :
'''

"""
    和三数之和一样
    确定两个数字之后，使用双指针 不过这个地方在while里面也加入了去重操作
"""

class Solution(object):
    def fourSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[List[int]]
        """
        # 三数之和 -> 二数之和 双指针
        # a_index  b_index  c_index -> 三指针?
        n = len(nums)
        nums = sorted(nums,reverse=False)
        res = []
        for a_index in range(n):
            if a_index >0 and nums[a_index] == nums[a_index-1]:
                continue
            for b_index in range(a_index + 1,n):
                if b_index > a_index + 1 and nums[b_index] == nums[b_index - 1] :
                    continue
                temp_target = target - nums[a_index] - nums[b_index]
                c_index = b_index + 1
                d_index = n-1
                while c_index < d_index:
                    if  nums[c_index] + nums[d_index] > temp_target:
                        d_index -= 1
                    elif nums[c_index] + nums[d_index] < temp_target:
                        c_index += 1
                    else :
                        res.append([nums[a_index],nums[b_index],nums[c_index],nums[d_index]])
                        c_index += 1
                    while c_index != b_index + 1 and c_index < d_index and nums[c_index] == nums[c_index-1] : #去重重复
                        c_index += 1
                    while d_index != n - 1 and c_index < d_index and nums[d_index]==nums[d_index+1]: # 去除重复
                        d_index -= 1
        return res


from flask import Flask, jsonify, request
from flask_cors import CORS

app = Flask(__name__)

@app.route("/api", methods=['POST'])
def api():

    r = request.json
    print(r)

    return '', 200

if __name__ == "__main__":
    app.run(port=5000)


import os
import binascii
from unittest import mock
import asyncio
import time
from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase
from tests.unit.lbrynet_daemon.test_ExchangeRateManager import get_dummy_exchange_rate_manager

from lbrynet.extras.wallet.manager import LbryWalletManager
from lbrynet.stream.stream_manager import StreamManager
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.dht.node import Node
from lbrynet.schema.claim import ClaimDict

def get_mock_node(peer):
    def mock_accumulate_peers(q1: asyncio.Queue, q2: asyncio.Queue):
        async def _task():
            pass

        q2.put_nowait([peer])
        return q2, asyncio.create_task(_task())

    mock_node = mock.Mock(spec=Node)
    mock_node.accumulate_peers = mock_accumulate_peers
    return mock_node

def get_mock_wallet(sd_hash, storage):
    claim = {
        "address": "bYFeMtSL7ARuG1iMpjFyrnTe4oJHSAVNXF",
        "amount": "0.1",
        "claim_id": "c49566d631226492317d06ad7fdbe1ed32925124",
        "claim_sequence": 1,
        "decoded_claim": True,
        "depth": 1057,
        "effective_amount": "0.1",
        "has_signature": False,
        "height": 514081,
        "hex": "",
        "name": "33rpm",
        "nout": 0,
        "permanent_url": "33rpm#c49566d631226492317d06ad7fdbe1ed32925124",
        "supports": [],
        "txid": "81ac52662af926fdf639d56920069e0f63449d4cde074c61717cb99ddde40e3c",
        "value": {
            "claimType": "streamType",
            "stream": {
                "metadata": {
                    "author": "",
                    "description": "",
                    "language": "en",
                    "license": "None",
                    "licenseUrl": "",
                    "nsfw": False,
                    "preview": "",
                    "thumbnail": "",
                    "title": "33rpm",
                    "version": "_0_1_0"
                },
                "source": {
                    "contentType": "image/png",
                    "source": sd_hash,
                    "sourceType": "lbry_sd_hash",
                    "version": "_0_0_1"
                },
                "version": "_0_0_1"
            },
            "version": "_0_0_1"
        }
    }
    claim_dict = ClaimDict.load_dict(claim['value'])
    claim['hex'] = binascii.hexlify(claim_dict.serialized).decode()

    async def mock_resolve(*args):
        await storage.save_claims([claim])
        return {
            claim['permanent_url']: claim
        }

    mock_wallet = mock.Mock(spec=LbryWalletManager)
    mock_wallet.resolve = mock_resolve
    return mock_wallet, claim['permanent_url']

class TestStreamManager(BlobExchangeTestBase):
    async def asyncSetUp(self):
        await super().asyncSetUp()
        file_path = os.path.join(self.server_dir, "test_file")
        with open(file_path, 'wb') as f:
            f.write(os.urandom(20000000))
        descriptor = await StreamDescriptor.create_stream(self.loop, self.server_blob_manager.blob_dir, file_path)
        self.sd_hash = descriptor.calculate_sd_hash()
        self.mock_wallet, self.uri = get_mock_wallet(self.sd_hash, self.client_storage)
        self.stream_manager = StreamManager(self.loop, self.client_config, self.client_blob_manager, self.mock_wallet,
                                            self.client_storage, get_mock_node(self.server_from_client))
        self.exchange_rate_manager = get_dummy_exchange_rate_manager(time)

    async def test_download_stop_resume_delete(self):
        self.assertSetEqual(self.stream_manager.streams, set())
        stream = await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager)
        stream_hash = stream.stream_hash
        self.assertSetEqual(self.stream_manager.streams, {stream})
        self.assertTrue(stream.running)
        self.assertFalse(stream.finished)
        self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file")))
        stored_status = await self.client_storage.run_and_return_one_or_none(
            "select status from file where stream_hash=?", stream_hash
        )
        self.assertEqual(stored_status, "running")

        await self.stream_manager.stop_stream(stream)

        self.assertFalse(stream.finished)
        self.assertFalse(stream.running)
        self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file")))
        stored_status = await self.client_storage.run_and_return_one_or_none(
            "select status from file where stream_hash=?", stream_hash
        )
        self.assertEqual(stored_status, "stopped")

        await self.stream_manager.start_stream(stream)
        await stream.downloader.stream_finished_event.wait()
        await asyncio.sleep(0.01)
        self.assertTrue(stream.finished)
        self.assertFalse(stream.running)
        self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file")))
        stored_status = await self.client_storage.run_and_return_one_or_none(
            "select status from file where stream_hash=?", stream_hash
        )
        self.assertEqual(stored_status, "finished")

        await self.stream_manager.delete_stream(stream, True)
        self.assertSetEqual(self.stream_manager.streams, set())
        self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file")))
        stored_status = await self.client_storage.run_and_return_one_or_none(
            "select status from file where stream_hash=?", stream_hash
        )
        self.assertEqual(stored_status, None)


"""
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'.
The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'.
Each move consists of turning one wheel one slot.

The lock initially starts at '0000', a string representing the state of the 4 wheels.

You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning
and you will be unable to open it.

Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

Example 1:
Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
Output: 6

Explanation:
A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
because the wheels of the lock become stuck after the display becomes the dead end "0102".

"""

class Solution:
    def getNeighbors(self, key: str) -> List[str]:
        neighbors = []
        for i in range(4):
            for j in [1, -1]:
                if int(key[i]) == 0 and j == -1:
                    dig = 9
                else:
                    dig = (int(key[i]) + j) % 10
                neighbors.append(key[:i]+str(dig)+key[i+1:])
        return neighbors

    def openLock(self, deadends: List[str], target: str) -> int:
        queue = []
        if not "0000" in deadends:
            queue.append(('0000', 0))
            visited = {'0000'}
        while queue:
            key, count = queue.pop(0)
            if key == target:
                return count
            for nkey in self.getNeighbors(key):
                if nkey in deadends:
                    continue
                if nkey not in visited:
                    queue.append((nkey, count+1))
                    visited.add(nkey)
        return -1


import dash
import dash_core_components as dcc
import dash_html_components as html
import matplotlib.pyplot as plt
from dash.dependencies import Input, Output
import plotly.offline as py
from plotly.graph_objs import *
import plotly.graph_objs as go
import dash_bootstrap_components as dbc
import folium
from folium import IFrame, FeatureGroup
import numpy as np
from PIL import Image
import json
import os
import base64
import glob
import pandas as pd
from folium.plugins import MarkerCluster

### Data
import pandas as pd
import pickle
### Graphing
import plotly.graph_objects as go
### Dash
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Output, Input
## Navbar
from navbar import Navbar

style1 = {'fillColor': '#00FFFFFF', 'lineColor': '#00FFFFFF','zoom_on_click':'False'}

nav = Navbar()

retval = os.getcwd()

grupos = ['CCHLA','CEAR','CCSA','CE','CCJ','CT','CBIOTEC','CCTA','CCEN','CCS','CCM']
dados = ['Quantidade de projetos em 2017','Quantidade de projetos em 2018','Quantidade de projetos em 2019','Quantidade de projetos em 2020']

dict_csv = { 'Quantidade de projetos em 2017' : 'Apoio/dados/dataset_2017.csv',
            'Quantidade de projetos em 2018' : 'Apoio/dados/dataset_2018.csv',
    		'Quantidade de projetos em 2019' : 'Apoio/dados/dataset_2019.csv',
            'Quantidade de projetos em 2020' : 'Apoio/dados/dataset_2020.csv'
}

def escala_mapa(max):
    step = (max/9)
    myscale=np.arange(1, max, step).tolist()
    myscale.extend([max])
    return myscale

dict_ajeita_ano = {'Quantidade de projetos em 2017': '2017', 'Quantidade de projetos em 2018': '2018', 'Quantidade de projetos em 2019': '2019','Quantidade de projetos em 2020':'2020'}

#state_data=pd.read_csv('C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\dados\\projetos_2017.csv', engine='python')
#geo_data = 'C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\ufpb_centros.json'

state_data=pd.read_csv('Apoio/Projetos_2017.csv', engine='python')
geo_data = 'Apoio/ufpb_centros.json'

professores_envolvidos ={'CBIOTEC2017': 6,
 'CBIOTEC2018': 9,
 'CBIOTEC2019': 10,
 'CBIOTEC2020': 8,
 'CCA2017': 81,
 'CCA2018': 84,
 'CCA2019': 90,
 'CCA2020': 90,
 'CCAE2017': 76,
 'CCAE2018': 90,
 'CCAE2019': 86,
 'CCAE2020': 85,
 'CCEN2017': 45,
 'CCEN2018': 46,
 'CCEN2019': 45,
 'CCEN2020': 77,
 'CCHLA2017': 78,
 'CCHLA2018': 102,
 'CCHLA2019': 94,
 'CCHLA2020': 160,
 'CCHSA2017': 65,
 'CCHSA2018': 81,
 'CCHSA2019': 74,
 'CCHSA2020': 96,
 'CCJ2017': 40,
 'CCJ2018': 45,
 'CCJ2019': 49,
 'CCJ2020': 46,
 'CCM2017': 56,
 'CCM2018': 83,
 'CCM2019': 85,
 'CCM2020': 93,
 'CCS2017': 246,
 'CCS2018': 281,
 'CCS2019': 266,
 'CCS2020': 332,
 'CCSA2017': 79,
 'CCSA2018': 80,
 'CCSA2019': 43,
 'CCSA2020': 84,
 'CCTA2017': 69,
 'CCTA2018': 69,
 'CCTA2019': 76,
 'CCTA2020': 95,
 'CE2017': 60,
 'CE2018': 53,
 'CE2019': 95,
 'CE2020': 97,
 'CEAR2017': 19,
 'CEAR2018': 21,
 'CEAR2019': 19,
 'CEAR2020': 21,
 'CI2017': 14,
 'CI2018': 25,
 'CI2019': 20,
 'CI2020': 18,
 'CT2017': 86,
 'CT2018': 69,
 'CT2019': 63,
 'CT2020': 91,
 'CTDR2017': 39,
 'CTDR2018': 22,
 'CTDR2019': 26,
 'CTDR2020': 45}

chama_ano_criacao = {
    'CCHLA': 1949
    ,'CEAR': 2011
    ,'CCSA': 1934
    ,'CE': 1978
    ,'CCJ':1949
    ,'CT': 1974
    ,'CBIOTEC':2011
    ,'CCTA':2012
    ,'CCEN': 1974
    ,'CCS': 1974
    ,'CCM': 2007
    ,'CCA': 1936
    ,'CCHSA': 2008
    ,'CCAE': 2006
    ,'CI':2012
    ,'CTDR': 2009
}

chama_departamentos = {
    'CCHLA': 11
    ,'CEAR': 2
    ,'CCSA': 6
    ,'CE': 7
    ,'CCJ':5
    ,'CT': 7
    ,'CBIOTEC':2
    ,'CCTA': 7
    ,'CCEN':9
    ,'CCS':13
    ,'CCM': 5
    ,'CCA': 7
    ,'CCHSA': 6
    ,'CCAE': 8
    ,'CTDR': 3
    ,'CI': 3
}

chama_cursos = {
    'CCHLA': ['Ciências Sociais','Comunicação em Mídias Digitais', 'Filosofia', 'História', 'Letras', 'Letras / Ead', 'Letras - Libras', 'Letras(Língua Espanhola)','Letras(Língua Francesa)','Letras(Línguas Clássicas)','Letras(Língua Inglesa)','Línguas Estrangeiras Aplicadas às Negociações Internacionais', 'Psicologia','Serviço Social','Tradução']
    ,'CEAR': ['Engenharia Elétrica', 'Engenharia de Energias Renovaveis']
    ,'CCSA': ['Admnistração', 'Admnistração Pública','Arquivologia','Biblioteconomia', 'Ciências Atuariais','Ciências Contábeis','Ciências Econômicas','Gestão Pública','Relações Internacionais','Tecnologia em Gestão Pública']
    ,'CE': ['Ciências das Religiões','Ciências Naturais','Pedagogia','Pedagogia - EAD', 'Pedagogia(Educação Do Campo)','Pedagogia(MSC)','Psicopedagogia(BACH)']
    ,'CCJ':['Direito']
    ,'CT': ['Arquitetura e Urbanismo','Engenharia Ambiental','Engenharia Civil','Engenharia De Alimentos','Engenharia De Materiais','Engenharia de Produção','Engenharia de Produção Mecânica','Engenharia Mecânica','Engenharia Química','Química Industrial']
    ,'CBIOTEC':['Biotecnologia']
    ,'CCTA': ['Artes Visuais','Cinema e Audiovisual','Comunicação Social','Dança','Educação Artística','Hotelaria', 'Jornalismo','Música','Música - Bacharelado', 'Música Popular', 'Radialismo','Regência De bandas E Fanfarras','Relações Públicas', 'Teatro(Bacharelado)','Teatro(Licenciatura)','Turismo']
    ,'CCEN':['Ciencias','Ciências Biológicas','Ciências Biológicas - EAD', 'Computação', 'Estatística','Física','Geografia','Matemática','Matemática - EAD', 'Química' ]
    ,'CCS':['Biomedicina','Educação Física','Educação Física - Licenciatura','Enfermagem','Farmácia','Fisioterapia','Fonoaudiologia','Nutrição','Odontologia','Terapia Ocupacional']
    ,'CCM': ['Medicina']
    ,'CCA': ['Agronomia','Ciências biológicas', 'Medicina Veterinaria','Química','Zootecnia']
    ,'CCHSA': ['Admnistração','Agroecologia','Agroindustria','Ciências Agrárias','Curso Superior de Tecnologia em Cooperativismo','Pedagogia']
    ,'CCAE': ['Admnistração','Antropologia','Ciência da Computação','Ciências Contábeis','Design','Ecologia','Hotelaria','Letras','Letras(Espanhol)','Letras(Inglês)','Matemática','Pedagogia','Secretariado Executivo Bilíngue','Sistemas de Informação']
    ,'CTDR': ['Gastronomia','Tecnologia de Alimentos','Tecnologia em Produção Sucroaalcoleira']
    ,'CI': ['Ciência da Computação','Ciência de Dados e Inteligência Artificial','Engenharia da Computação','Matemática Computacional']
}

chama_assessor = {
    'CCHLA': 'Nívia Pereira'
    ,'CEAR': 'Jose Mauricio Ramos de Souza Neto'
    ,'CCSA': 'Danielle Vieira'
    ,'CE': 'Quézia Furtado, Mª da Conceição Miranda'
    ,'CCJ':'Ludmila Cerqueira'
    ,'CT': 'Aurélia Idrogo, Luzia Camboim'
    ,'CBIOTEC':'Elisângela A. de Moura Kretzschmar'
    ,'CCTA': 'Luceni Caetano'
    ,'CCEN':'Jane Torelli'
    ,'CCS': 'Rosenés Lima'
    ,'CCM': 'André Bonifácio'
    ,'CCA': 'Fábio Mielezrsk'
    ,'CCHSA': 'Catarina de Medeiros'
    ,'CCAE': 'Jocélio de Oliveira'
    ,'CI': 'José Miguel Aroztegui'
    ,'CTDR': 'Ana Braga'
}

chama_diretor = {
    'CCHLA': 'Mônica Nóbrega'
    ,'CEAR': 'Zaqueu Ernesto da Silva '
    ,'CCSA': 'Walmir Rufino Da Silva'
    ,'CE': 'Wilson Honorato Aragão'
    ,'CCJ':'Fredys Orlando Souto'
    ,'CT': 'Antônio de Mello Villar'
    ,'CBIOTEC':'Valdir de Andrade Braga'
    ,'CCTA': 'José David Campos Fernandes'
    ,'CCEN':'José Roberto Soares do Nascimento'
    ,'CCS':'João Euclides Fernandes Braga'
    ,'CCM': 'Eduardo Sérgio Moura Souza'
    ,'CCA': 'Manuel Bandeira de Albuquerque'
    ,'CCHSA': 'Terezinha Domiciano Martins'
    ,'CCAE': 'Maria Angeluce Soares Perônico Barbotin'
    ,'CI': 'Hamilton Soares da Silva'
    ,'CTDR': 'José Marcelino Oliveira Cavalheiro'
}

chama_vice = {
    'CCHLA': 'Rodrigo Freire de Carvalho e Silva'
    ,'CEAR': 'Euler Cássio Tavares de Macedo'
    ,'CCSA': 'Aldo Leonardo Cunha Callado'
    ,'CE': 'Swamy de Paula Lima Soares'
    ,'CCJ': 'Valfredo de Andrade Aguiar Filho'
    ,'CT': 'Tarciso Cabral da Silva'
    ,'CBIOTEC': 'Fabíola da Cruz Nunes'
    ,'CCTA': 'Ulisses Carvalho da Silva'
    ,'CCEN': 'Severino Francisco de Oliveira'
    ,'CCS':'Fabiano Gonzaga Rodrigues'
    ,'CCM': 'Eutília Freire'
    ,'CCA': 'Ricardo Romão Guerra'
    ,'CCHSA': 'Pedro Germano Antonio Nunes'
    ,'CCAE': 'Alexandre Scaico'
    ,'CI': 'Lucídio dos Anjos Formiga Cabral'
    ,'CTDR': 'João Andrade da Silva'
}

centro_extenso = {
    'CCHLA': 'Centro de Ciências Humanas, Letras e Artes'
    ,'CEAR': 'Centro de Energias Alternativas e Renováveis'
    ,'CCSA': 'Centro de Ciências Sociais Aplicadas'
    ,'CE': 'Centro de Educação'
    ,'CCJ': 'Centro de Ciências Jurídicas'
    ,'CT': 'Centro de Tecnologia'
    ,'CBIOTEC': 'Centro de Biotecnologia'
    ,'CCTA': 'Centro de Comunicação, Turismo e Artes'
    ,'CCEN': 'Centro de Ciências Exatas e da Natureza'
    ,'CCS':'Centro de Ciências da Saúde'
    ,'CCM': 'Centro de Ciências Médicas'
    ,'CCA': 'Centro de Ciencias Agrárias'
    ,'CCHSA': 'Centro de Ciências Humanas, Sociais e Agrárias'
    ,'CCAE': 'Centro de Ciências Aplicadas e Educação'
    ,'CI': 'Centro de Informática'
    ,'CTDR': 'Centro de Tecnologia e Desenvolvimento Regional'
}

def chama_projetos(file,dado):
    state_data_1=pd.read_csv(dict_csv[dado], engine='python')
    filtered = [file]
    print(state_data_1)
    state_data_1 = state_data_1[state_data_1['centros'].isin(filtered)]
    lista= list(state_data_1['qtd_projeto'])
    return lista[0]

dict_coordenadas = {
    'cbiotec' : [-7.140993, -34.846455],
    'ccen'  : [-7.139640, -34.845020],
    'cchla' : [-7.139370, -34.850374],
    'ccj' :  [-7.141978, -34.848935],
    'ccm' : [-7.136423, -34.840567 ],
    'ccs' :  [-7.135673, -34.841516],
    'ccsa' :  [-7.141069, -34.849936],
    'ccta' : [-7.137422, -34.849572],
    'ce' : [-7.139994, -34.850124],
    'cear' : [-7.141625, -34.850556],
    'ct' : [-7.142505, -34.850309],
    'cca'  : [-6.973692, -35.716273],
    'ccae'  : [-6.829091, -35.118770],
    'cchsa'  : [-6.752077, -35.647532],
    'ci':[-7.162211,-34.817228],
    'ctdr':[-7.163018,-34.817989]
}

#folder ='C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\logos'
folder ='Apoio/logos'

extension = '*'
separator = ','
extension = '*.' + extension
os.chdir(folder)
files_logos= glob.glob(extension)

os.chdir(retval)

#folder_1 ='C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\arquivos_json'
#folder_1 ='C:Apoio\\arquivos_json'
folder_1='Apoio/arquivos_json'
os.chdir(folder_1)
files_json= glob.glob(extension)
os.chdir(retval)

#folder_2 ='C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\dados'
folder_2 ='Apoio/dados'
os.chdir(folder_2)
files_dados= glob.glob(extension)
os.chdir(retval)

tooltip = "Clique para abrir a imagem"
html1 = ''.format

def limpa_nome_arquivo_json(logo):
    files=logo.replace('json','')
    files=files.replace('.','')
    return files

def limpa_nome_arquivo(logo):
    files=logo.replace('jpeg','')
    files=files.replace('jpg','')
    files=files.replace('png','')
    files=files.replace('.','')
    return files

def gera_cloropleth(geo_data,state_data,files_dados,mapa_,dado,grupos):

    state_data_1=[]
    state_data_1=pd.read_csv(dict_csv[dado], engine='python')
    #geo_data = 'C:\\Users\\Pessoal\\Desktop\\ODE\\choropleth\\gp_1.json'
    #geo_data = 'Apoio/choropleth/json_divisao_centros.json'
    with open('Apoio/choropleth/json_divisao_centros.json') as jsonfile:
        input_dict = json.load(jsonfile)

    lista_features = [x for x in input_dict['features'] if x['id'] in grupos]

    #geo_data = json.dumps(lista_features)
    geo_data ={'type': 'FeatureCollection','features': lista_features}

    filtered = grupos
    state_data_1 = state_data_1[state_data_1['centros'].isin(filtered)]

    #myscale = (state_data_1['qtd_projeto'].quantile((0,0.12,0.22,0.32,0.42,0.52,0.72,0.82,0.92,1))).tolist()
    maxi=max(list(state_data_1['qtd_projeto']))
    myscale=escala_mapa(maxi)
    myscale=[float(i) for i in myscale]
    try:
        folium.Choropleth(
                geo_data = geo_data,
                name='Choropleth',
                data=state_data_1,
                columns=['centros', 'qtd_projeto'],
                key_on='feature.id',
                fill_color='YlGn',
                fill_opacity=0.7,
                line_opacity=0.2,
                legend_name='Quantidade de projetos',
                threshold_scale=myscale,
                #show=False,
                #overlay=False
            ).add_to(mapa_)
    except KeyError:
        pass

    #folium.LayerControl().add_to(map)

def gera_camadas_ufpb(arquivo_json,mapa_,logo):
    #AQUIII
    picture1 = base64.b64encode(open('Apoio/logos/' + logo ,'rb').read()).decode()
    #img = Image.open('Apoio/logos/' + logo)

    iframe1 = IFrame(html1(picture1), width=200+20, height=200+20)
    #icon1 = folium.features.CustomIcon('C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\logos\\' + logo, icon_size=(20,20))
    #camadas_ufpb = os.path.join('C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\arquivos_json\\' + arquivo_json)
    camadas_ufpb = os.path.join('Apoio/arquivos_json/' + arquivo_json)

    arquivo_json=limpa_nome_arquivo_json(arquivo_json)

    camada=folium.GeoJson(camadas_ufpb,name=arquivo_json, tooltip='Clique para abrir a imagem',style_function=lambda x:style1).add_to(mapa_)

    #camada.add_child(folium.Popup(dict_centros[arquivo_json]))
    camada.add_child(folium.Popup(iframe1,width=200+20,height=200+20))

    camada.add_to(mapa_)

def gera_icones_da_ufpb(logo,dict_logo,dict_coordenadas,html1,tooltip,mapa_,arquivo_json,dado):
    #AQUIII
    #picture1 = base64.b64encode(open('C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\logos\\' + logo ,'rb').read()).decode()
    files=limpa_nome_arquivo(logo)
    file = files.upper()
    cur=chama_cursos[file]

    if dado == 0:
        html1=f"""

 Informações sobre o {file}

    Nome do Centro: {centro_extenso[file]}

    Ano de criação: {chama_ano_criacao[file]}

    Número de departamentos: {chama_departamentos[file]}

    Cursos: {', '.join(str(x) for x in cur)}

    Diretor: {chama_diretor[file]}

    Vice-Diretor: {chama_vice[file]}

    Assessor(es): {chama_assessor[file]}

    """
    else:
        html1=f"""

 Informações sobre o {file}

    Nome do Centro: {centro_extenso[file]}

    Ano de criação: {chama_ano_criacao[file]}

    Número de departamentos: {chama_departamentos[file]}

    Cursos: {', '.join(str(x) for x in cur)}

    Diretor: {chama_diretor[file]}

    Vice-Diretor: {chama_vice[file]}

    Assessor(es): {chama_assessor[file]}

    {dado}: {chama_projetos(file,dado)}

    Quantidade de professores Envolvidos: {professores_envolvidos[file + dict_ajeita_ano[dado]]}

    """
    #picture1 = base64.b64encode(open('Apoio/logos/' + logo ,'rb').read()).decode()
    arquivo_json=limpa_nome_arquivo_json(arquivo_json)
    #iframe1 = IFrame(html1(picture1), width=200+20, height=200+20)
    icon1 = folium.features.CustomIcon('Apoio/logos/' + logo, icon_size=(20,20))

    ifr = IFrame(html=html1, width=500, height=300)
    popup1 = folium.Popup(ifr, max_width=2650)
    #popup1 = folium.Popup(dict_centros[arquivo_json],max_width=600)
    folium.Marker(location=dict_coordenadas[files],popup= popup1,tooltip='Clique para um maior conhecimento sobre centro',icon=icon1).add_to(mapa_)

def mapa_da_ufpb(tooltip, files_logos,dict_coordenadas,files_json,geo_data,state_data, files_dados,mapa_,flag,grupos,dado):
    files_json = []
    files_logos = []
    if 'CTDR' in grupos:
        files_json.extend(['CTDR.json'])
        files_logos.extend([ 'ctdr.png'])
    if 'CI' in grupos:
        files_json.extend(['CI.json'])
        files_logos.extend([ 'ci.png'])
    if 'CCA' in grupos:
        files_json.extend(['CCA.json'])
        files_logos.extend([ 'cca.png'])
    if 'CCAE' in grupos:
        files_json.extend(['CCAE.json'])
        files_logos.extend([ 'ccae.png'])
    if 'CCHSA' in grupos:
        files_json.extend(['CCHSA.json'])
        files_logos.extend([ 'cchsa.png'])
    if 'CCJ' in grupos:
        files_json.extend(['CCJ.json'])
        files_logos.extend([ 'ccj.png'])
    if 'CT' in grupos:
        files_json.extend(['CT.json'])
        files_logos.extend([ 'ct.png'])
    if 'CBIOTEC' in grupos:
        files_json.extend(['CBIOTEC.json'])
        files_logos.extend(['cbiotec.png'])
    if 'CCHLA' in grupos:
        files_json.extend(['CCHLA.json'])
        files_logos.extend([ 'cchla.png'])
    if 'CEAR' in grupos:
        files_json.extend(['CEAR.json'])
        files_logos.extend([ 'cear.png'])
    if 'CCSA' in grupos:
        files_json.extend(['CCSA.json'])
        files_logos.extend([ 'ccsa.png'])
    if 'CE' in grupos:
        files_json.extend(['CE.json'])
        files_logos.extend(['ce.png'])
    if 'CCTA' in grupos:
        files_json.extend(['CCTA.json'])
        files_logos.extend(['ccta.png'])
    if 'CCEN' in grupos:
        files_json.extend(['CCEN.json'])
        files_logos.extend(['ccen.png'])
    if 'CCHLA' in grupos:
        files_json.extend(['CCHLA.json'])
        files_logos.extend([ 'cchla.png'])
    if 'CCS' in grupos:
        files_json.extend(['CCS.json'])
        files_logos.extend([ 'ccs.png'])
    if 'CCM' in grupos:
        files_json.extend(['CCM.json'])
        files_logos.extend(['ccm.png'])

    if flag == 'nao' or dado == 0:
        for arquivo_json,logo in zip(files_json,files_logos):
            gera_camadas_ufpb(arquivo_json,mapa_,logo)
    for arquivo_json,logo in zip(files_json,files_logos):
        gera_icones_da_ufpb(logo,logo,dict_coordenadas,html1,tooltip,mapa_,arquivo_json,dado)
    if flag == 'sim' and grupos != [] and dado != 0:
        print('cheguei',flush=True)
        gera_cloropleth(geo_data,state_data,files_dados,mapa_,dado,grupos)
    #mapa_.save("C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\mapa_ufpb_centros.html")
    mapa_.save("Apoio/mapa_ufpb_centros.html")
tab_selected_style = {
    'font-size': '70%',
    'padding': '6px'
}

tab_style = { #Estilos das Tabs
    'borderBottom': '1px solid #d6d6d6',
    'padding': '6px',
    'font-size': '75%',
    'fontSize' : '12'
    }
#####
tabs = html.Div([
    dcc.Tabs(id='tabs', value='tab-3', children=[
        dcc.Tab(label='Areia', value='tab-1', style=tab_style, selected_style=tab_selected_style),
         dcc.Tab(label='Bananeiras', value='tab-2', style=tab_style, selected_style=tab_selected_style),
          dcc.Tab(label='João Pessoa', value='tab-3', style=tab_style, selected_style=tab_selected_style),
           dcc.Tab(label='Mangabeira', value='tab-5', style=tab_style, selected_style=tab_selected_style),
            dcc.Tab(label='Mamanguape', value='tab-4', style=tab_style, selected_style=tab_selected_style),
])
    ,html.Br()])

card_content = [
    dbc.CardHeader("Filtros do Mapa",style={'font-size':24, 'textAlign':'center'}),
    dbc.CardBody(
        [
        tabs,
        html.H4("Escolha o grupo desejado:", style={'font-size':19,'margin-top':'14px'}),
        dcc.Dropdown(
        id = 'grupos',
        options=[
            {'label': j, 'value': j} for j in grupos
        ],
        value=['Todos os centros'],
        multi=True,
    searchable=False
    ),

    html.Div(html.Br()),
    html.H4("Deseja analisar o mapa pelo quantitativo de projetos por ano?", style={'font-size':19}),

    dbc.RadioItems(
                    options=[
                        {'label': 'Sim', 'value': 'sim'},
                        {'label': 'Não', 'value': 'nao'},

                    ],
                    id='flag',
                    value='1',
                    inline = True,
                    labelStyle={'display': 'inline-block','margin-bottom':'10px'}
                ),
    html.Div([
    html.H4("Escolha o ano para visualizar o mapa:", style={'font-size':19}),

    dcc.Dropdown(
        id = 'dados',
        options=[
            {'label': j, 'value': j} for j in dados
        ],
        value=0,
         multi=False,
    searchable=False,
         style={'margin-bottom':'10px'}

    ),],
    id='choropleth',
    style = {'display': 'none'}),
        ]
    ),
]

jumbotron = dbc.Card(card_content,  outline=True)

card_content_3 = [
    dbc.CardHeader("Mapa da UFPB",style={'font-size':24, 'textAlign':'center'}),
    dbc.CardBody(
        [
            html.Iframe(id='mapa', srcDoc=open('Apoio/mapa_ufpb_centros.html', 'r').read(),width='100%',height='580px'),
        ]
    ),
]

jumbotron_2 = dbc.Card(card_content_3,  outline=True)

body_1 =html.Div([

        dbc.Row(
           [
               dbc.Col(
                  [

                jumbotron,

                   ], md=4

               ),
              dbc.Col([
     	      jumbotron_2

                    ], md=8 ),

                ],no_gutters=True
            ),

])

def mapa():
    layout = html.Div([
    nav,

	body_1,
    html.Div([], id='value-container', style={'display': 'none'})

     #html.Iframe(id='mapa', srcDoc=open('C:\\Users\\gabri\\OneDrive\\Área de Trabalho\\Pasta de backup\\ODE\\mapa_ufpb_centros.html', 'r').read(), width='100%', height='430'),

     #html.Iframe(id='mapa', srcDoc=open('Apoio/mapa_ufpb_centros.html', 'r').read(), width='100%', height='430'),
    ])
    return layout


# Создать класс, описывающий группу студентов - `Group`.
# Данный класс хранит студентов в виде списка объектов `Student` также реализованного в виде соответствующего класса.
# В классах реализовать необходимай набор атрибутов
# (Например, класс `Student` должен иметь атрибуты `name`, `age`, `grades`), а также
# необходимый набор методов экземпляра для работы с этими экземплярами.

class Group:
    def __init__(self, gr_name, num_of_students, lst_of_students):
        self._gr_name = self.verify_gr_name(gr_name)
        self._num_of_students = self.verify_num_of_students(num_of_students)
        self._lst_of_students = self.verify_lst_of_students(lst_of_students)

    @property  # Getter <Name of Group>
    def gr_name(self):
        return self._gr_name

    @property  # Getter <Num of Students>
    def num_of_students(self):
        return self._num_of_students

    @property  # Getter <List of Students>
    def lst_of_students(self):
        return self._lst_of_students

    @gr_name.setter  # Setter <Group name>
    def gr_name(self, gr_name):
        self.verify_gr_name(gr_name)

    def verify_gr_name(self, gr_name):
        try:
            if len(gr_name) == 5 and gr_name.startswith(('AS', 'AM', 'AK', 'AE', 'AI', 'AV', 'AA', 'AT', 'AD')) == True and (isinstance(int(gr_name[2:]), int)) == True:
                self._gr_name = gr_name
                return self._gr_name
            else:
                print('Ввод группы должен начинаться с кода (AS, AM, AK, AE, AI, AV, AA, AT, AD) и заканчиваться трёмя числами.\n')
        except:
            print('Ошибка! Ввод группы должен начинаться с кода (AS, AM, AK, AE, AI, AV, AA, AT, AD) и заканчиваться трёмя числами.\n')

    @num_of_students.setter  # Setter <Number of students>
    def num_of_students(self, num_of_students):
        self.verify_num_of_students(num_of_students)

    def verify_num_of_students(self, num_of_students):
        try:
            if 0 <= num_of_students <= 30:
                self._num_of_students = num_of_students
                return self._num_of_students
            else:
                print("Недопустимое количество студентвов. Введите число от 1 до 30.\n")
        except:
            print('Неправильный ввод данных. Введите число от 1 до 30.\n')

    @lst_of_students.setter  # Setter <list of students>
    def lst_of_students(self, lst_of_students):
        verify_lst_of_students(lst_of_students)

    def verify_lst_of_students(self, lst_of_students):
        try:
            if type(lst_of_students) == list:
                self._lst_of_students = lst_of_students
                return self._lst_of_students
            else:
                print(r"Первоначальный список студентов должен подаваться в форме [<Имя_студента>, <Имя_студента>]")
        except:
            print(r"Ошибка! Первоначальный список студентов должен подаваться в форме [<Имя_студента>, <Имя_студента>]")

    def display_info(self):
        lst_of_names = [i.name for i in self._lst_of_students]
        lst_of_names = [len(x) for x in lst_of_names]
        max_len_of_name = max(lst_of_names)

        lst_of_numbers = [i.num_in_gr for i in self.lst_of_students]
        lst_of_numbers.sort()

        if self._num_of_students == 1:
            print("В группе под номером", self._gr_name, " один студент.")
            for i in self._lst_of_students:
                print('•', '{:>2}'.format(i.num_in_gr), '•', i.name + ' '*(max_len_of_name-len(i.name)), '• Оценки:', end = ' ')
                for x in range(len(i.grades)):
                    if x < len(i.grades)-1:
                        print(i.grades[x], end = ', ')
                    else:
                        print(i.grades[x], end = '.')

        elif 2 <= self._num_of_students <= 4:
            print("В группе под номером", self._gr_name, self._num_of_students, "студента.")
            print('Список студентов: ')
            for num in lst_of_numbers:
                for i in self.lst_of_students:
                    if num == i.num_in_gr:
                        print('•', '{:>2}'.format(i.num_in_gr), '•', i.name + ' '*(max_len_of_name-len(i.name)), '• Оценки:', end = ' ')
                        for x in range(len(i.grades)):
                            if x < len(i.grades)-1:
                                print(i.grades[x], end = ', ')
                            else:
                                print(i.grades[x], end = '.')
                        break

        else:
            print("В группе под номером", self._gr_name, self._num_of_students, "студентов.")
            print('Список студентов: ')
            for num in lst_of_numbers:
                for i in self.lst_of_students:
                    if num == i.num_in_gr:
                        print('•', '{:>2}'.format(i.num_in_gr), '•', i.name + ' '*(max_len_of_name-len(i.name)), '• Оценки:', end = ' ')
                        for x in range(len(i.grades)):
                            if x < len(i.grades)-1:
                                print(i.grades[x], end = ', ')
                            else:
                                print(i.grades[x], end = '.')
                        break

class Student:
    def __init__(self, name, age, grades, num_in_gr, gr_num):
        self._name = self.verify_name(name)
        self._age = self.verify_age(age)
        self._grades = self.verify_grades(grades)
        self._num_in_gr = self.verify_num_in_gr(num_in_gr)
        self._gr_num = self.verify_gr_num(gr_num)

    @property  # Getter <Name>
    def name(self):
        return self._name

    @property  # Getter <Age>
    def age(self):
        return self._age

    @property  # Getter <Grades>
    def grades(self):
        return self._grades

    @property  # Getter <Num in group>
    def num_in_gr(self):
        return self._num_in_gr

    @property  # Getter <Group Number>
    def gr_num(self):
        return self._gr_num

    @name.setter  # Setter <Name>
    def name(self, name):
        verify_name(name)

    def verify_name(self, name):
        try:
            if name.isalpha() == True:
                self._name = name
                return self._name
            else:
                print("Недопустимое имя, возможно использовать лишь алфавит.")
        except:
            print("Ошибка! Недопустимое имя, возможно использовать лишь алфавит.")

    @age.setter  # Setter <Age>
    def age(self, age):
        self.verify_age(age)

    def verify_age(self, age):
        try:
            if 1 <= age <= 115:
                self._age = age
                return self._age
            else:
                print("Недопустимый возраст. Возможен возраст от 1 до 115.")
        except:
            print("Ошибка! Недопустимый возраст. Возможен возраст от 1 до 115.")

    @grades.setter  # Setter <Grades>
    def grades(self, grades):
        self.verify_grades(grades)

    def verify_grades(self, grades):
        try:
            lst = list(map(int, grades.split(' ')))
            if (all( 1 <= i <= 100 for i in lst)) == True:
                self._grades = lst
                return self._grades
            else:
                print('Возможен ввод лишь целых чисел от 1 до 100. Ввод в формате <94 71 63...>')
        except:
            print('Ошибка! Возможен ввод лишь целых чисел от 1 до 100. Ввод в формате <94 71 63...>')

    @num_in_gr.setter  # Setter <Number in group>
    def num_in_gr(self, num_in_gr):
        self.verify_num_in_gr(num_in_gr)

    def verify_num_in_gr(self, num_in_gr):
        try:
            if num_in_gr in range(1, 31):
                self._num_in_gr = num_in_gr
                return self._num_in_gr
            else:
                print("Введите номер от 1 до 30.")
        except:
            print("Ошибка! Введите номер от 1 до 30.")

    @gr_num.setter  # Setter <Group number>
    def gr_num(self, gr_num):
        self.verify_gr_num(gr_num)

    def verify_gr_num(self, gr_num):
        try:
            if len(gr_num) == 5 and gr_num.startswith(('AS', 'AM', 'AK', 'AE', 'AI', 'AV', 'AA', 'AT', 'AD')) == True and (isinstance(int(gr_num[2:]), int)) == True:
                self._gr_num = gr_num
                return self._gr_num
            else:
                print('Ввод группы должен начинаться с кода (AS, AM, AK, AE, AI, AV, AA, AT, AD) и заканчиваться трёмя числами.')
        except:
            print('Ошибка! Ввод группы должен начинаться с кода (AS, AM, AK, AE, AI, AV, AA, AT, AD) и заканчиваться трёмя числами.')

    def display_info(self):
        print("Студент по имени", self._name, "возрастом в", self._age, "лет состоит в группе", self._gr_num, "под номером", self._num_in_gr, "имея следующие баллы: ", end = '')
        for x in range(len(self.grades)):
            if x < len(self.grades)-1:
                print(self.grades[x], end = ', ')
            else:
                print(self.grades[x], '\b.')

    def verify_input(self):
        if self.name == None or self.age == None or self.grades == None or self.num_in_gr == None or self.gr_num == None:
            print('Данные введены неверно, давайте попробуем ещё раз :с\n')
            return False
        else:
            print('Данные введены верно, поздравляем!')
            return True

if __name__ == '__main__':

    print('\t')
    print('На данный момент у нас есть три студента. Давайте расскажем о них.')
    Alex = Student('Alexey', 20, '56 74 98 31 94', 4, 'AS193')
    Alex.display_info()
    Dan = Student('Daniil', 17, '75 86 79 64 97', 14, 'AS193')
    Dan.display_info()
    Bogdan = Student('Bogdan', 18, '61 79 80 76 84', 5, 'AS193')
    Bogdan.display_info()

    print('\t')
    print('Также у нас есть группа AS193, в которой они втроём состоят. Теперь о нашей группе.')
    as193 = Group('AS193', 3, [Dan, Alex, Bogdan])
    as193.display_info()

    print('\t')
    print('Недавно у Даниила был День Рождения. Теперь ему 18. Давайте обновим информацию и снова выведём её.')
    Dan.age = 18
    Dan.display_info()
    lst_of_all_groups = [as193]

    print('\t')
    print('Отлично, всё работает! А мы, поздравив Даниила с Днём Рождения, двигаемся дальше.')
    print('На данный момент у нас есть три студента и одна группа.')
    print('Давайте выберем, что будет делать дальше:')
    print('  Добавим новых студентов в группу AS193 (нажмите 1)\n  Создадим новую группу (нажмите 2) ?')

    while (True):
        n = int(input('Ввод: '))
        if n == 1 or n == 2:
            break
        else:  # неправильный ввод
            print('Читерить нельзя! Только 1 или 2 :3')

    if n == 1:  # добавляем студентов в AS193
        print('\nМы решили добавить студентов в группу AS193, отлично (это лучшая группа, отличный выбор).')
        print('Теперь решим, мы уже знаем, сколько студентов будем добавлять (1) или будем добавлять их по одному (2)?')

        while (True):
            x = int(input('Ваш выбор: '))
            if x == 1 or x == 2:
                break
            else:  # неправильный ввод
                print('Давайте введём данные правильно :с')

        if x == 1:  # знаем, сколько студентов будем добавлять

            while (True):
                num = int(input('В группу AS193 мы добавим столько студентов: '))
                if num >= 1:
                    break
                else:
                    print('Мы можем добавить только положительное число студентов :)')

            print()
            for i in range(num):
                print('Добавляем {}-го студента в группу AS193.\n'.format(i + 4))

                while (True):
                    name = input('Имя студента (только буквы): ')
                    age = int(input('Возраст студента (1-115): '))
                    grades = input('Оценки студента в формате <65 78 92 ...>: ')
                    num_in_gr = int(input('Номер студента по журналу (1-30): '))

                    student = Student(name, age, grades, num_in_gr, 'AS193')
                    if student.verify_input() == True:
                        print('\nМы добавили нового студента:')
                        student.display_info()
                        as193.num_of_students += 1
                        as193.lst_of_students.append(student)
                        break

            print('\nОтлично! Теперь у нас в группе AS193 {} студентов. Давайте посмотрим новый состав группы:'.format(num+3))
            as193.display_info()

        elif x == 2:  # добавлять в AS193 по одному
            while(True):
                print('Добавляем {}-го студента в группу AS193.\n'.format(as193.num_of_students + 1))

                while (True):
                    name = input('Имя студента (только буквы): ')
                    age = int(input('Возраст студента (1-115): '))
                    grades = input('Оценки студента в формате <65 78 92 ...>: ')
                    num_in_gr = int(input('Номер студента по журналу (1-30): '))

                    student = Student(name, age, grades, num_in_gr, 'AS193')
                    if student.verify_input() == True:
                        print('\nМы добавили нового студента:')
                        student.display_info()
                        as193.num_of_students += 1
                        as193.lst_of_students.append(student)
                        break

                while (True):
                    m = int(input('Мы будем добавлять ещё одного студента? (0 - нет, 1 - да): '))
                    if m == 0:
                        print('\nХорошо, тогда с AS193 пока закончили! Вот как выглядит обновлённая группа:')
                        as193.display_info()
                        print()
                        break
                    elif m == 1:
                        break
                    else:
                        print('Ошибка :с, давайте попробуем ещё раз...')
                break

        while (True):  # будем ли создавать другие группы или закончим
            n = int(input('\nТеперь вопрос. Мы будем добавлять студентов в другие группы? Наш выбор (1 - да, 0 - нет): '))
            if n == 0:
                print('Конец программы! В итоге мы дополнили нашу группу AS193.\n')
                break
            elif n == 1:
                n = 2
                break
            else:
                print('Ввод не верен :"c')

    if n == 2:  # добавляем студентов в другие группы
        print('\nДавайте создадим новые группы из студентов.')

        while True:  # создаём новую группу

            print('Ввод группы должен начинаться с кода (AS, AM, AK, AE, AI, AV, AA, AT, AD) и заканчиваться трёмя числами.\n')
            while (True):
                name_gr = input('Имя группы: ')
                if len(name_gr) == 5 and name_gr.startswith(('AS', 'AM', 'AK', 'AE', 'AI', 'AV', 'AA', 'AT', 'AD')) == True and (isinstance(int(name_gr[2:]), int)) == True:
                    break
                else:
                    print('Неверный ввод.')

            name_gr = Group(name_gr, 0, [])

            print('Теперь решим, мы уже знаем, сколько студентов будем добавлять (1) или будем добавлять их по одному (2)?')
            while (True):
                x = int(input('Ваш выбор: '))
                if x == 1 or x == 2:
                    break
                else:  # неправильный ввод
                    print('Давайте введём данные правильно :с')

            if x == 1:  # знаем, сколько студентов будем добавлять

                while (True):
                    num = int(input('В группу {} мы добавим столько студентов: '.format(name_gr.gr_name)))
                    if num >= 1:
                        break
                    else:
                        print('Мы можем добавить только положительное число студентов :)')

                print()
                for i in range(num):  # добавляем студентов
                    print('Добавляем {}-го студента в группу {}.\n'.format(i+1, name_gr.gr_name))

                    while (True):
                        name = input('Имя студента (только буквы): ')
                        age = int(input('Возраст студента (1-115): '))
                        grades = input('Оценки студента в формате <65 78 92 ...>: ')
                        num_in_gr = int(input('Номер студента по журналу (1-30): '))

                        student = Student(name, age, grades, num_in_gr, name_gr.gr_name)
                        if student.verify_input() == True:
                            print('\nМы добавили нового студента:')
                            student.display_info()
                            name_gr.num_of_students += 1
                            name_gr.lst_of_students.append(student)
                            break

                print('\nОтлично! Теперь у нас в группе', name_gr.gr_name, num, 'студентов. Давайте посмотрим новый состав группы:')
                name_gr.display_info()
                lst_of_all_groups.append(name_gr)
                break

            elif x == 2:  # добавлять в группу по одному
                while(True):
                    print('Добавляем {}-го студента в группу {}.\n'.format(name_gr.num_of_students + 1, name_gr.gr_name))

                    while (True):
                        name = input('Имя студента (только буквы): ')
                        age = int(input('Возраст студента (1-115): '))
                        grades = input('Оценки студента в формате <65 78 92 ...>: ')
                        num_in_gr = int(input('Номер студента по журналу (1-30): '))

                        student = Student(name, age, grades, num_in_gr, name_gr.gr_name)
                        if student.verify_input() == True:
                            print('\nМы добавили нового студента:')
                            student.display_info()
                            name_gr.num_of_students += 1
                            name_gr.lst_of_students.append(student)
                            break

                    while (True):
                        n = int(input('Мы будем добавлять ещё одного студента? (0 - нет, 1 - да): '))
                        if n == 0 or n == 1:
                            break
                        else:
                            print('Ошибка :с, давайте попробуем ещё раз...')

                    if n == 0:
                        print('\nХорошо, тогда с {} пока закончили! Вот как выглядит обновлённая группа:'.format(name_gr.gr_name))
                        name_gr.display_info()
                        lst_of_all_groups.append(name_gr)
                        break

            print('\nВиу, дела идут отлично. Будем создавать ещё одну группу (1 - да, 0 - нет)?')
            while(True):
                k = int(input('И мы...: '))
                if k == 1 or k == 0:
                    break
                else:
                    print('Ошибка, давайте попытаемся ещё раз.')

            if k == 0:
                print('Отлично, тогда закончили!\n')
                break

    print('\n\nВот и конец.')
    print('Вот какие группы у нас в итоге вышли:\n')
    for i in lst_of_all_groups:
        print(i.display_info())
        print()

    print("\nThat's the real end. Thank you very much for everything!")


import csv
input = open('Global_Msg_List.csv')

list_of_ids = []
def main():
    # read file
    from os import path
    file_path = path.abspath("D:\RobiPython\\WarningDispatchers.xml")
    file = open(file_path, "r")
    out  = open("workfile.txt", 'w')
    lines = file.readlines()
    file.close()

    sub = 'WarningName="'
    sub1 = '" Type="HMI'

    length = len(sub)
    lentgth1 = len(sub1)

    for line in lines:
        while sub in line:
                begin = line.find(sub) + length
                end = line.find(sub1,begin)

                #print(line[begin:end])
                list_of_ids.append(line[begin:end])

                line = line[0:begin-length] + line[begin:]
                end = end - length
                line = line[0:end] + line[end+lentgth1:]
    #print(list_of_ids)

main()
def make():
    print("Aici incepe smenul")
    with open('something_else.csv', 'w', newline='') as output_file:
        writer = csv.writer(output_file)
        writer.writerow(next(csv.reader(input)))
    #for row in csv.reader(input):
        for row in list_of_ids:
            input.seek(0)
            for row1 in csv.reader(input):
                if row1[0]==row :
                    print(row1)
                    writer.writerow(row1)
            #print(row[0])
        #   if row[0] in list_of_ids or row[0]=='ID':
         #       writer.writerow(row)
make()


#!/bin/env python3
####################################################################################################
## Copyright (C) 2016 Princess Margaret Bioinformatics and HPC Core - All Rights Reserved
## You may freely use, distribute and modify copies of this code within any of the systems currently
## owned and operated by the University Health Network and the Bioinformatics and HPC Core.
## If you require pieces of this code for any other purposes outside of these systems
## please contact the Bioinformatics and HPC Core directly for permission.
##
## The Bioinformatics and HPC Core makes no claims as to the usability or reliability of
## this code. Use for clinical purposes must only be done by those at UHN who are
## authorized to do so using the Standard Operating Practices that have been developed specifically
## for this purpose.
####################################################################################################

"""
  Finds all the BAM in the source directory and run the recommended GATK pre-processing steps: Picard
  MarkDuplicates, realignment around indels, and base quality score recalibration. Options
  and filters chosen based on GATK best practices.
"""

import argparse
import os
import glob

import pmgctools
import qsub

KNOWN_1000G = '/mnt/work1/data/genomes/human/hg19/variantcallingdata/1000G_phase1.indels.hg19.vcf'
KNOWN_MILLS = '/mnt/work1/data/genomes/human/hg19/variantcallingdata/Mills_and_1000G_gold_standard.indels.hg19.vcf'

def init():
    parser = argparse.ArgumentParser(
        description='Finds all the BAM in the source directory and run the recommended GATK pre-processing steps')
    parser.add_argument('-s', '--source', required=True, help='Source directory')
    parser.add_argument('-o', '--output', required=True, help='Output directory')
    parser.add_argument('-c', '--coverage',
                        help="coverage to downsample to at a given locus, enter an integer (e.g. 1000) or gatk to "
                             "use GATK default settings. If not provided, no downsampling will be performed.")
    parser.add_argument('-l', '--log', default='process.log', help='Log file name')
    parser.add_argument('-q', '--qsub', default="qsub", help='qsub directory')
    parser.add_argument('-D', '--dry-run', action='store_true', dest='dry', default=False,
                        help='dry run, will create qsub scripts but will not submit to the cluster')
    parser.add_argument('-I', '--ini', required=False, help='INI file.')
    parser.add_argument('-d', '--dbsnp', help='current dbSNP reference in VCF format')
    parser.add_argument('-g', '--bed', help='BED file containing intervals of interest')
    parser.add_argument('-S', '--species',
                        help='Species default=HUMAN. For non-human data extra Mills/1000Genomes indel resources, '
                             'which are provided by default to RealignerTargetCreator & BaseRecalibrator will not '
                             'be used.')
    parser.add_argument('-n', '--no-markduplicate', action='store_true', default=False, dest='no_markdup',
                        help='Do not run markduplicate.')
    parser.add_argument('-t', '--no-bqsr', action='store_true', default=False, dest='bqsr',
                        help='BQSR will not be run; needed for datasets < 150 Mbases')
    parser.add_argument('-C', '--config', default=None,
                        help='cocleaning config file. Put all samples for cocleaning in one line delimited with '
                             'space or ,')
    parser.add_argument('-Q', '--queue', default=None, help='Cluster queue you want to submit to.')
    options = parser.parse_args()
    return options

def mark_duplicate(source, outputdir, sample, waitlist=None, **other_qsub_options):
    """
    GATK Picard markduplicate
    :param source: source directory contains bam files need to be processed
    :param outputdir: output directory
    :param sample: sample name or bam file name to process
    :param waitlist: grid engine job waiting list
    :param other_qsub_options: other options for qsub script
    :return: job name, markdup_<sample>
    """
    tools = ['picard', 'samtools']
    modules = pmgctools.check_vars(tools)
    wait = ",".join(waitlist) if waitlist is not None else None
    tmpdir = os.path.join(outputdir, pmgctools.tmpdir())

    if sample.endswith('.bam'):
        sample = sample[:-4]
    dedup = os.path.join(outputdir, sample + '.dedup.bam')
    metrics = os.path.join(outputdir, sample + '.dedup')
    picard_dir = 'picard_dir' if pmgctools.get_var('picard_dir') else 'EBROOTPICARD' #uhn or CC software

    cmd = 'mkdir -p {}\n'.format(tmpdir)
    cmd += "java -Xmx12g -Djava.io.tmpdir={} -jar ${}/picard.jar MarkDuplicates".format(tmpdir, picard_dir)
    cmd += " INPUT={} OUTPUT={} METRICS_FILE={} ASSUME_SORTED=true MAX_RECORDS_IN_RAM=100000 VALIDATION_STRINGENCY=SILENT CREATE_INDEX=true".format(os.path.join(source, sample + '.bam'), dedup,
                                                                           metrics)
    cmd += "\nrm -rf {}".format(tmpdir)

    return qsub.qsub('markdup_' + sample, cmd, modules=modules, waitlist=wait, other='cpu=4|mem=20gb|walltime=72:00:00', **other_qsub_options)

def indel_realignment(source, output, sample, bed=None, dbsnp=None, species='Human', coverage=None, smalldataset=False,
                      waitlist=None, extension='.dedup.bam', remove_source=True, **other_qsub_options):
    """
    GATK indel realignment
    :param source: source directory of the result of markduplicate (mark_duplicate result directory)
    :param sample: sample names to process, simple sample or multiple samples in list to co-clean
    :param bed: region file
    :param dbsnp: dbsnp vcf file
    :param species: HUMAN or not
    :param coverage: downsampling info, see source code
    :param smalldataset: small data set. do not run BSQR
    :param waitlist: job waiting list
    :param other_qsub_options: other options for qsub script
    :return: job name, Realignement_<sample>
    """
    tools = ['gatk', 'samtools']
    envs = pmgctools.check_vars(['REF'])
    if not bed:
        bed = pmgctools.get_var('bed')

    modules = pmgctools.check_vars(tools)
    wait = ",".join(waitlist) if waitlist is not None else None
    source = os.path.abspath(source)
    tmpdir = pmgctools.tmpdir()

    region = ""
    if bed:
        region = "--intervals " + os.path.abspath(bed) + " --interval_padding 100"
    ref = os.path.abspath(envs["REF"])
    if not dbsnp:
        dbsnp = os.path.abspath(pmgctools.check_vars(["dbSNP"])["dbSNP"])
    if species.upper() == "HUMAN":
        known_1000g = pmgctools.get_var("KNOWN_1000G")
        if known_1000g is None:
            known_1000g = KNOWN_1000G
        known_mills = pmgctools.get_var("KNOWN_MILLS")
        if known_mills is None:
            known_mills = KNOWN_MILLS
        known = "-known {} -known {}".format(known_1000g, known_mills)
    else:
        known = "-known {}".format(dbsnp)

    if not coverage:
        coverage = "-dt None"
    elif coverage is "gatk":
        coverage = ""
    elif coverage.isdigit():
        coverage = "-dcov " + coverage
    else:
        print("Error: wrong downsampling value " + coverage)

    input = "-I "
    if isinstance(sample, str):
        sample = [sample]

    input += ' -I '.join([os.path.join(source, i + extension) for i in sample])
    name = '_'.join(sample)[:200]
    intervals = name + '.intervals'

    # Start to work in the directory
    if not os.path.exists(output):
        os.makedirs(output)
    cmd = 'cd {}\nmkdir {}\n'.format(output, tmpdir)

    cmd += "java -Xmx8g -Djava.io.tmpdir={} -jar $gatk_dir/GenomeAnalysisTK.jar -T RealignerTargetCreator --disable_auto_index_creation_and_locking_when_reading_rods -nt 4 -R {}" \
           " {} -o {} {} {} {}".format(tmpdir, ref, input, intervals, coverage, region, known)
    cmd += "\njava -Xmx4g -Djava.io.tmpdir={} -jar $gatk_dir/GenomeAnalysisTK.jar --disable_auto_index_creation_and_locking_when_reading_rods -T IndelRealigner {} -nWayOut " \
           ".realigned.bam -targetIntervals {} -R {} {} {} -compress 0".format(tmpdir, input, intervals, ref, coverage,
                                                                               known)

    # remove intermediate files
    cmd += '\nrm -rf {}'.format(tmpdir)
    cmd += '\nrm {}'.format(intervals)
    new_extension = extension.replace('.bam', '.realigned.bam')
    for f in sample:
        if smalldataset:
            cmd += '\nmv {} {}'.format(f + new_extension, f + '.processed.bam')
            cmd += '\nmv {} {}'.format(f + new_extension.replace('.bam', '.bai'), f + '.processed.bai')
        if remove_source:
            cmd += '\nrm {}'.format(f + extension.replace('.bam', '.ba*'))

    cmd += '\n'

    return qsub.qsub('Realignment_' + name, cmd, modules=modules, waitlist=wait, other='cpu=8|mem=16gb|walltime=72:00:00', **other_qsub_options)

def bqsr(source, sample, bed=None, dbsnp=None, species='Human', coverage=None, extension='.dedup.realigned.bam',
         waitlist=None, **other_qsub_options):
    """
    GATK BQSR wrapper
    :param source: source directory of the result of indel_realignment (indel_realignment result directory)
    :param sample: sample names to process
    :param bed: region file
    :param dbsnp: :param dbsnp: dbsnp vcf file
    :param species: HUMAN or not
    :param coverage: downsampling info, see source code
    :param waitlist: job waiting list
    :param other_qsub_options: other options for qsub script
    :return: job name, BSQR_<sample>
    """
    tools = ['gatk']
    envs = pmgctools.check_vars(['REF'])
    modules = pmgctools.check_vars(tools)
    wait = ",".join(waitlist) if waitlist is not None else None
    tmpdir = os.path.join(source, pmgctools.tmpdir())

    if not bed:
        bed = pmgctools.get_var('bed')
    region = ""
    if bed:
        region = "--intervals " + bed + " --interval_padding 100"
    if not coverage:
        coverage = "-dt None"
    elif coverage is "gatk":
        coverage = ""
    elif coverage.isdigit():
        coverage = "-dcov " + coverage
    else:
        print("Error: wrong downsampling value " + coverage)
    recaldata = os.path.join(source, sample + ".recal_data.grp")
    ref = envs["REF"]
    if not dbsnp:
        dbsnp = pmgctools.check_vars(["dbSNP"])["dbSNP"]
    input = os.path.join(source, sample + extension)
    cmd = 'mkdir {}\n'.format(tmpdir)
    cmd += "java -Xmx4g -Djava.io.tmpdir={}  -jar $gatk_dir/GenomeAnalysisTK.jar -T BaseRecalibrator --disable_auto_index_creation_and_locking_when_reading_rods -nct 8 -I {} -o {}" \
          " -R {} -knownSites {} -rf BadCigar -cov ReadGroupCovariate -cov ContextCovariate -cov CycleCovariate -cov" \
          " QualityScoreCovariate {} {}".format(tmpdir, input, recaldata, ref, dbsnp, coverage, region)
#    if species.upper() == "HUMAN":
#        known_1000g = pmgctools.get_var("KNOWN_1000G")
#        if known_1000g is None:
#            known_1000g = KNOWN_1000G
#        known_mills = pmgctools.get_var("KNOWN_MILLS")
#        if known_mills is None:
#            known_mills = KNOWN_MILLS
#        cmd += " -knownSites {} -knownSites {}".format(known_1000g, known_mills)
    recal = os.path.join(source, sample + '.processed.bam')
    cmd += "\njava -Xmx4g -Djava.io.tmpdir={} -jar $gatk_dir/GenomeAnalysisTK.jar -T PrintReads --disable_auto_index_creation_and_locking_when_reading_rods -nct 8 -I {} -R {}" \
           " -BQSR {} -o {} -rf BadCigar {}".format(tmpdir, input, ref, recaldata, recal, coverage)
    cmd += '\nrm {} {} {}\n'.format(recaldata, input, input.replace('.bam', '.bai'))
    cmd += '\nrm -rf {}'.format(tmpdir)

    return qsub.qsub('BQSR_' + sample, cmd, modules=modules, waitlist=wait, other='cpu=8|mem=12gb|walltime=72:00:00', **other_qsub_options)

def process_bam(source, outputdir, samples, smalldataset=False, bed=None, dbsnp=None, species='Human',
                coverage=None, waitlist=None, no_markdup=False, **other_qsub_options):
    if isinstance(samples, str):
        samples = [samples]

    wait = None
    remove_source = False
    if not no_markdup:
        wait = []
        remove_source = True
        for sample in samples:
            wait.append(mark_duplicate(source, outputdir, sample, waitlist=waitlist, **other_qsub_options))
    else:
        wait = waitlist

    indel_wait = []
    dup_source = source if no_markdup else outputdir
    extension = '.bam' if no_markdup else '.dedup.bam'
    indel_wait.append(
        indel_realignment(dup_source, outputdir, samples, bed, dbsnp, species, coverage, smalldataset, waitlist=wait,
                          extension=extension, remove_source=remove_source, **other_qsub_options))
    bqsr_wait = []
    if not smalldataset:
        extension = '.dedup.realigned.bam' if not no_markdup else '.realigned.bam'
        for sample in samples:
            bqsr_wait.append(
                bqsr(outputdir, sample, bed, dbsnp, species, coverage, extension=extension, waitlist=indel_wait,
                     **other_qsub_options))

    return bqsr_wait + indel_wait

if __name__ == '__main__':
    args = init()
    if args.ini:
        pmgctools.read_vars(args.ini)
    pmgctools.check_vars(['gatk', 'samtools', 'picard', 'REF'])
    source, outputdir, config, log, qsubdir, dry, dbsnp, bed, species, coverage, smalldataset, config = args.source, \
                                                                                args.output, args.config, args.log, args.qsub, args.dry, args.dbsnp, args.bed, args.species, args.coverage, \
                                                                                args.bqsr, args.config
    # species command line > INI file, default: HUMAN
    if not species:
        species = pmgctools.get_var('SPECIES')
    if not species:
        species = 'HUMAN'

    remove_source = False if args.no_markdup else True

    if config is None:
        bams = glob.glob(os.path.join(source, '*.bam'))
        for bamfile in bams:
            sample = os.path.basename(bamfile)[:-4]  # remove .bam
            process_bam(source=source, outputdir=outputdir, samples=sample, smalldataset=smalldataset, bed=bed,
                        dbsnp=dbsnp, species=species, no_markdup=args.no_markdup,
                        coverage=coverage, log=log, qsub=qsubdir, dry=dry, queue=args.queue)

    else:
        with open(config) as f:
            for line in f:
                samples = line.rstrip().replace('.bam', '').replace('Sample_', '').replace(',', ' ').split()
                process_bam(source=source, outputdir=outputdir, samples=samples, smalldataset=smalldataset, bed=bed,
                            dbsnp=dbsnp, species=species, no_markdup=args.no_markdup,
                            coverage=coverage, log=log, qsub=qsubdir, dry=dry, queue=args.queue)