import os
import json
import argparse
from datetime import datetime

from .util import pad_vocab_size

def str_list(x):
    return x.split(",")

def int_list(x):
    return list(map(int, x.split(",")))

def float_list(x):
    return list(map(float, x.split(",")))

def str2bool(v):
    if v.lower() in ("yes", "true", "t", "y", "1"):
        return True
    elif v.lower() in ("no", "false", "f", "n", "0"):
        return False
    else:
        raise argparse.ArgumentTypeError("Unsupported value encountered.")

def get_parser(parser=None):
    if parser is None:
        parser = argparse.ArgumentParser(
            description="Train GPT-2 on your custom dataset."
        )

    # data and cfg
    parser.add_argument(
        "--dataset",
        metavar="PATH",
        type=str,
        required=True,
        help="Input file, directory (utf-8 text, or preencoded .npz files).",
    )
    parser.add_argument(
        "--combine",
        metavar="CHARS",
        type=int,
        default=50000,
        help="Concatenate input files with <|endoftext|> "
        "separator into chunks of this minimum size",
    )
    parser.add_argument(
        "--encoding",
        type=str,
        default="utf-8",
        help="Set the encoding for reading and writing files.",
    )
    parser.add_argument(
        "--cfg_dir",
        metavar="CONFIG",
        type=str,
        default="models/117M",
        help="folder contains `encoder.json` and `vocab.bpe`",
    )
    parser.add_argument(
        "--hparams_file",
        metavar="HPARAMS",
        type=str,
        help="path of `hparams.json`, use following arguments if absent.",
    )
    # model
    parser.add_argument("--n_vocab", type=int, default=50257, help="vocab size")
    parser.add_argument("--n_ctx", type=int, default=1024, help="length of context")
    parser.add_argument("--n_embd", type=int, default=768, help="embedding/hidden size")
    parser.add_argument(
        "--n_head", type=int, default=12, help="number of attention head"
    )
    parser.add_argument("--n_layer", type=int, default=12, help="number of layer")
    parser.add_argument(
        "--seq_len", metavar="SEQUENCE", type=int, default=1024, help="sequence length"
    )
    parser.add_argument(
        "--embedding_dropout", type=float, default=0.1, help="embedding dropout rate"
    )
    parser.add_argument(
        "--hidden_dropout", type=float, default=0.1, help="output dropout rate"
    )
    parser.add_argument(
        "--attention_dropout", type=float, default=0.1, help="attention dropout rate"
    )
    parser.add_argument(
        "--make-vocab-size-divisible-by",
        type=int,
        default=128,
        help="Pad the vocab size to be divisible by this value."
        "This is added for computational efficieny reasons.",
    )
    parser.add_argument(
        "--use_big_fc", type=str2bool, default=False, help="use big fc in attn"
    )
    parser.add_argument(
        "--use_fp16", type=str2bool, default=False, help="Whether to use use fp16"
    )
    parser.add_argument(
        "--checkpoint-activations",
        action="store_true",
        help="Checkpoint activation to allow for training "
        "with larger models, sequences, and batch sizes.",
    )
    parser.add_argument(
        "--checkpoint_matmul",
        type=str2bool,
        default=False,
        help="include matmul in checkpoint activations or not",
    )
    parser.add_argument(
        "--checkpoint_variable",
        type=str2bool,
        default=True,
        help="include variable in checkpoint or not",
    )
    # optimizer
    parser.add_argument(
        "--optimizer", type=str, default="adam", help="Optimizer. <adam|sgd>."
    )
    parser.add_argument(
        "--weight-decay",
        type=float,
        default=0.01,
        help="Weight decay coefficient for L2 regularization.",
    )
    parser.add_argument(
        "--clip-grad",
        type=float,
        default=1.0,
        help="Gradient clipping based on global L2 norm.",
    )
    parser.add_argument(
        "--adam-beta1",
        type=float,
        default=0.9,
        help="First coefficient for computing running averages of"
        "gradient and its square",
    )
    parser.add_argument(
        "--adam-beta2",
        type=float,
        default=0.999,
        help="Second coefficient for computing running averages of"
        "gradient and its square",
    )
    parser.add_argument(
        "--adam-eps",
        type=float,
        default=1e-08,
        help="Term added to the denominator to improve numerical stability",
    )
    parser.add_argument(
        "--learning_rate",
        metavar="LR",
        type=float,
        default=0.00002,
        help="Learning rate for Adam",
    )
    # train step
    parser.add_argument(
        "--total_batch_size", metavar="SIZE", type=int, default=1, help="Batch size"
    )
    parser.add_argument(
        "--iter_num", type=int, default=110, help="total iterations to run"
    )
    parser.add_argument(
        "--loss_print_every_n_iter",
        type=int,
        default=10,
        required=False,
        help="print loss every n iteration",
    )
    parser.add_argument(
        "--model_save_every_n_iter",
        type=int,
        default=0,
        required=False,
        help="save model every n iteration",
    )
    parser.add_argument(
        "--model_save_dir",
        type=str,
        default="model_save",
        required=False,
        help="model save directory",
    )
    parser.add_argument(
        "--save_last_snapshot",
        type=str2bool,
        default=False,
        required=False,
        help="save model snapshot for last iteration",
    )
    parser.add_argument(
        "--model_load_dir", type=str, default=None, help="model load directory"
    )
    parser.add_argument(
        "--log_dir", type=str, default="./output", help="log info save directory"
    )
    # distribute
    parser.add_argument("--gpu_num_per_node", type=int, default=1)
    parser.add_argument(
        "--num_nodes", type=int, default=1, help="node/machine number for training"
    )
    parser.add_argument(
        "--node_ips",
        type=str_list,
        default=["192.168.1.13", "192.168.1.14"],
        help='nodes ip list for training, devided by ",", length >= num_nodes',
    )
    parser.add_argument(
        "--ctrl_port", type=int, default=50051, help="ctrl_port for multinode job"
    )
    parser.add_argument(
        "--wte_split", type=int, default=-1, help="token embd model split axis"
    )
    parser.add_argument(
        "--wpe_split", type=int, default=-1, help="pos embd model split axis"
    )
    parser.add_argument(
        "--decoder_model_parallel",
        type=str2bool,
        default=False,
        help="is model parallel for decoder blocks",
    )
    parser.add_argument(
        "--model-parallel-size", type=int, default=1, help="Size of the model parallel."
    )
    parser.add_argument(
        "--parallel-embedding", action="store_true", help="distributed embedding",
    )
    parser.add_argument(
        "--parallel-decoder", action="store_true", help="distributed decoder",
    )
    parser.add_argument(
        "--parallel-loss",
        action="store_true",
        help="distributed softmax cross entropy loss",
    )
    # misc
    parser.add_argument(
        "--metric-print-format",
        type=str,
        default="normal",
        help="metric print format <normal|table>",
    )
    return parser

def print_args(args):
    print("=".ljust(66, "="))
    print(
        "Running {}: num_gpu_per_node = {}, num_nodes = {}.".format(
            "GPT-2", args.gpu_num_per_node, args.num_nodes
        )
    )
    print("=".ljust(66, "="))
    for arg in vars(args):
        print("{} = {}".format(arg, getattr(args, arg)))
    print("-".ljust(66, "-"))
    print("Time stamp: {}".format(str(datetime.now().strftime("%Y-%m-%d-%H:%M:%S"))))

def get_args():
    parser = get_parser()
    args = parser.parse_args()

    if args.hparams_file:
        assert os.path.isfile(args.hparams_file)
        print("use hparams.json", args.hparams_file, "some arguments will be replaced.")
        with open(args.hparams_file) as f:
            hparams = json.load(f)
            args.n_vocab = hparams["n_vocab"]
            args.n_ctx = hparams["n_ctx"]
            args.n_embd = hparams["n_embd"]
            args.n_head = hparams["n_head"]
            args.n_layer = hparams["n_layer"]

    # batch_size = args.batch_size_per_device * args.gpu_num_per_node * args.num_nodes
    args.batch_size = args.total_batch_size

    args.padded_vocab_size = pad_vocab_size(
        args.n_vocab,
        args.make_vocab_size_divisible_by,
        args.num_nodes * args.gpu_num_per_node,
        args.parallel_embedding,
    )

    print_args(args)
    return args

if __name__ == "__main__":
    get_args()


import os
import pandas as pd
import urx
import time
import msvcrt

#This program should be run in terminal in Windows

mypose = [] # unit: m, rad
mytime= [] # unit: s

dt = 0.03 #sample period (s)
N = int(input("\nNo.: "))

#connect to the robot, using 30003 to read data
rob = urx.Robot("192.168.1.2",use_rt=True)

path = os.getcwd()
filePose = (path+"\\Pose_{}.csv").format(N)

print("\nInput any key to start:")

msvcrt.getch() # wait key to start
print("Start!")
print("\nInput #Enter to stop")

#set the robot to freedrive mode
rob.set_freedrive(val=True,timeout=3600)

startTime = time.time()
while True:
    if msvcrt.kbhit():
        key = msvcrt.getch() #wait the Enter key to stop
        if key == b'\r':
            break
    mytime.append(time.time()-startTime)
    mypose.append(rob.get_myPose())
    # myspeed.append(rob.get_mySpeed())
    time.sleep(dt)
endTime = time.time()

#end the freedrive mode
rob.set_freedrive(val=False)
rob.close()

print("\nEnd!")
print("Program time: ",endTime-startTime,"s\n")

##========================================
# Save the data

column_label1 = ['x','y','z','rx','ry','rz']

pd_pose = pd.DataFrame(columns=column_label1,index=mytime,data=mypose)
pd_pose.to_csv(filePose)


def parse(self, inventory, loader, path, cache=True):
    if (not HAS_GOOGLE_LIBRARIES):
        raise AnsibleParserError(('gce inventory plugin cannot start: %s' % missing_required_lib('google-auth')))
    super(InventoryModule, self).parse(inventory, loader, path)
    config_data = {

    }
    config_data = self._read_config_data(path)
    if self.get_option('use_contrib_script_compatible_sanitization'):
        self._sanitize_group_name = self._legacy_script_compatible_group_sanitization
    params = {
        'filters': self.get_option('filters'),
        'projects': self.get_option('projects'),
        'scopes': self.get_option('scopes'),
        'zones': self.get_option('zones'),
        'auth_kind': self.get_option('auth_kind'),
        'service_account_file': self.get_option('service_account_file'),
        'service_account_contents': self.get_option('service_account_contents'),
        'service_account_email': self.get_option('service_account_email'),
    }
    self.fake_module = GcpMockModule(params)
    self.auth_session = GcpSession(self.fake_module, 'compute')
    query = self._get_query_options(params['filters'])
    if self.get_option('retrieve_image_info'):
        project_disks = self._get_project_disks(config_data, query)
    else:
        project_disks = None
    if cache:
        cache = self.get_option('cache')
        cache_key = self.get_cache_key(path)
    else:
        cache_key = None
    cache_needs_update = False
    if cache:
        try:
            results = self._cache[cache_key]
            for project in results:
                for zone in results[project]:
                    self._add_hosts(results[project][zone], config_data, False, project_disks=project_disks)
        except KeyError:
            cache_needs_update = True
    if ((not cache) or cache_needs_update):
        cached_data = {

        }
        for project in params['projects']:
            cached_data[project] = {

            }
            params['project'] = project
            zones = params['zones']
            link = (self._instances % project)
            resp = self.fetch_list(params, link, query)
            if (('items' in resp) and resp['items']):
                for (key, value) in resp.get('items').items():
                    if ('instances' in value):
                        zone = key[6:]
                        if ((not zones) or (zone in zones)):
                            self._add_hosts(value['instances'], config_data, project_disks=project_disks)
                            cached_data[project][zone] = value['instances']
    if cache_needs_update:
        self._cache[cache_key] = cached_data


from flask import Flask, render_template
import subprocess

app = Flask(__name__)

@app.route('/', methods=['GET'])
def index(name=None):
    return render_template('hello.html', name=name)

@app.route('/b', methods=['GET'])
def b_start():
    subprocess.call(['python3', 'alarmclock.py'])
    return 'Hello'

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


import colander

from ichnaea.models import Radio
from ichnaea.api.locate.schema_v1 import LOCATE_V1_SCHEMA
from ichnaea.api.locate.tests.base import (
    BaseLocateTest,
    CommonLocateErrorTest,
    CommonLocateTest,
    CommonPositionTest,
)
from ichnaea.tests.base import (
    AppTestCase,
    TestCase,
)
from ichnaea.tests.factories import (
    CellShardFactory,
    WifiShardFactory,
)

class TestSchema(TestCase):

    schema = LOCATE_V1_SCHEMA

    def test_empty(self):
        data = self.schema.deserialize({})
        self.assertEqual(data, {
            'blue': (),
            'carrier': None,
            'cell': (),
            'considerIp': True,
            'fallbacks': {'ipf': True, 'lacf': True},
            'homeMobileCountryCode': None,
            'homeMobileNetworkCode': None,
            'wifi': ()})

    def test_consider_ip(self):
        data = self.schema.deserialize({'considerIp': False})
        self.assertEqual(data['fallbacks']['ipf'], False)
        data = self.schema.deserialize({'considerIp': 'false'})
        self.assertEqual(data['fallbacks']['ipf'], False)
        data = self.schema.deserialize({'considerIp': 'true'})
        self.assertEqual(data['fallbacks']['ipf'], True)
        data = self.schema.deserialize({'considerIp': False, 'fallbacks': {}})
        self.assertEqual(data['fallbacks']['ipf'], True)

    def test_invalid_radio_field(self):
        with self.assertRaises(colander.Invalid):
            self.schema.deserialize({'cellTowers': [{
                'radioType': 'umts',
            }]})

    def test_multiple_radio_fields(self):
        data = self.schema.deserialize({'cellTowers': [{
            'radio': 'gsm',
            'radioType': 'wcdma',
        }]})
        self.assertEqual(data['cell'][0]['radio'], 'wcdma')
        self.assertFalse('radioType' in data['cell'][0])

class LocateV2Base(BaseLocateTest, AppTestCase):

    url = '/v1/geolocate'
    metric_path = 'path:v1.geolocate'
    metric_type = 'locate'

    @property
    def ip_response(self):
        london = self.geoip_data['London']
        return {
            'location': {'lat': london['latitude'],
                         'lng': london['longitude']},
            'accuracy': london['radius'],
            'fallback': 'ipf',
        }

    def check_model_response(self, response, model,
                             region=None, fallback=None, **kw):
        expected_names = set(['location', 'accuracy'])

        expected = super(LocateV2Base, self).check_model_response(
            response, model,
            region=region,
            fallback=fallback,
            expected_names=expected_names,
            **kw)

        data = response.json
        location = data['location']
        self.assertAlmostEqual(location['lat'], expected['lat'])
        self.assertAlmostEqual(location['lng'], expected['lon'])
        self.assertAlmostEqual(data['accuracy'], expected['accuracy'])
        if fallback is not None:
            self.assertEqual(data['fallback'], fallback)

class TestView(LocateV2Base, CommonLocateTest, CommonPositionTest):

    def test_cell(self):
        cell = CellShardFactory()
        self.session.flush()

        query = self.model_query(cells=[cell])
        query['radioType'] = cell.radio.name
        del query['cellTowers'][0]['radioType']
        query['cellTowers'][0]['signalStrength'] = -70
        query['cellTowers'][0]['timingAdvance'] = 1

        res = self._call(body=query)
        self.check_model_response(res, cell)
        self.check_stats(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.result',
                ['key:test', 'region:none', 'fallback_allowed:false',
                 'accuracy:medium', 'status:hit', 'source:internal']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:medium', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])

    def test_partial_cell(self):
        cell = CellShardFactory()
        self.session.flush()

        # simulate one neighboring incomplete cell
        query = self.model_query(cells=[cell])
        query['cellTowers'][0]['psc'] = cell.psc

        cell_two = query['cellTowers'][0].copy()
        del cell_two['locationAreaCode']
        del cell_two['cellId']
        cell_two['psc'] = cell.psc + 1
        query['cellTowers'].append(cell_two)

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_wifi(self):
        wifi = WifiShardFactory()
        offset = 0.00001
        wifis = [
            wifi,
            WifiShardFactory(lat=wifi.lat + offset),
            WifiShardFactory(lat=wifi.lat + offset * 2),
            WifiShardFactory(lat=None, lon=None),
        ]
        self.session.flush()

        query = self.model_query(wifis=wifis)
        wifi_query = query['wifiAccessPoints']
        wifi_query[0]['channel'] = 6
        wifi_query[0]['signalStrength'] = -50
        wifi_query[1]['frequency'] = 2437
        wifi_query[2]['signalStrength'] = -130
        wifi_query[3]['signalToNoiseRatio'] = 13
        wifi_query[3]['ssid'] = 'my-wifi'

        res = self._call(body=query)
        self.check_model_response(res, wifi, lat=wifi.lat + 0.000005)
        self.check_stats(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.result',
                ['key:test', 'region:none', 'fallback_allowed:false',
                 'accuracy:high', 'status:hit', 'source:internal']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])

    def test_cell_mcc_mnc_strings(self):
        # mcc and mnc are officially defined as strings, where '01' is
        # different from '1'. In practice many systems ours included treat
        # them as integers, so both of these are encoded as 1 instead.
        # Some clients sends us these values as strings, some as integers,
        # so we want to make sure we support both.
        cell = CellShardFactory(mnc=1)
        self.session.flush()

        query = self.model_query(cells=[cell])
        query['cellTowers'][0]['mobileCountryCode'] = str(cell.mcc)
        query['cellTowers'][0]['mobileNetworkCode'] = '01'

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_cell_radio_in_celltowers(self):
        # This test covers a bug related to FxOS calling the
        # geolocate API incorrectly.
        cell = CellShardFactory()
        self.session.flush()

        query = self.model_query(cells=[cell])
        query['cellTowers'][0]['radio'] = cell.radio.name
        del query['cellTowers'][0]['radioType']

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_cell_radiotype_in_celltowers(self):
        # This test covers an extension to the geolocate API
        cell = CellShardFactory()
        self.session.flush()

        query = self.model_query(cells=[cell])
        query['cellTowers'][0]['radioType'] = cell.radio.name

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_cell_radio_in_celltowers_dupes(self):
        # This test covers a bug related to FxOS calling the
        # geolocate API incorrectly.
        cell = CellShardFactory()
        self.session.flush()

        query = self.model_query(cells=[cell])
        query['cellTowers'][0]['radio'] = cell.radio.name
        del query['cellTowers'][0]['radioType']

        cell_two = query['cellTowers'][0].copy()
        query['cellTowers'].append(cell_two)

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_inconsistent_cell_radio(self):
        cell = CellShardFactory(radio=Radio.wcdma, radius=15000, samples=10)
        cell2 = CellShardFactory(radio=Radio.gsm, radius=35000, samples=5,
                                 lat=cell.lat + 0.0002, lon=cell.lon)
        self.session.flush()

        query = self.model_query(cells=[cell, cell2])
        query['radioType'] = Radio.lte.name
        query['cellTowers'][0]['radio'] = 'wcdma'
        query['cellTowers'][1]['radio'] = cell2.radio.name
        del query['cellTowers'][0]['radioType']
        del query['cellTowers'][1]['radioType']

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_inconsistent_cell_radio_type(self):
        cell = CellShardFactory(radio=Radio.wcdma, radius=15000, samples=10)
        cell2 = CellShardFactory(radio=Radio.gsm, radius=35000, samples=5,
                                 lat=cell.lat + 0.0002, lon=cell.lon)
        self.session.flush()

        query = self.model_query(cells=[cell, cell2])
        query['radioType'] = Radio.lte.name
        query['cellTowers'][0]['radio'] = 'lte'

        res = self._call(body=query)
        self.check_model_response(res, cell)

    def test_cdma_cell(self):
        # Specifying a CDMA radio type works,
        # but the information is ignored.
        cell = CellShardFactory(radio=Radio.gsm, radius=15000)
        cell2 = CellShardFactory(radio=Radio.gsm, radius=35000,
                                 lat=cell.lat + 0.0002, lon=cell.lon)
        cell2.radio = Radio.cdma
        self.session.flush()

        query = self.model_query(cells=[cell, cell2])
        res = self._call(body=query)
        self.check_model_response(res, cell)

class TestError(LocateV2Base, CommonLocateErrorTest):

    def test_apikey_error(self):
        super(TestError, self).test_apikey_error(db_errors=1)

    def test_database_error(self):
        super(TestError, self).test_database_error(db_errors=9)


# -*- coding: cp1252 -*-
import pandas as pd
import django
import numpy as np
import re, os, xlsxwriter, math
import win32com.client as win32
from win32com.client import Dispatch

def is_int(s):
    try:
        int(s)
        return True
    except ValueError:
        return False
path="."
def round_down(n, decimals=0):
    multiplier = 10 ** decimals
    return math.floor(n * multiplier) / multiplier
def round_up(n, decimals=0):
    multiplier = 10 ** decimals
    return math.ceil(n * multiplier) / multiplier

#raw_input("CHANGE CODE IF MAIN NUMBER ISNīT FIRST NUMBER IN FILENAME")
class list_generator():
#   path = raw_input("path:%")
    path = "."
#   raw_input("start_define_lists")
    column_name_list=["FREQUENCY (MHz)", "_pow_(dBm)"]
    cal = pd.read_csv(str(path+"/"+"cal.csv"), header=0, names=[column_name_list[0], "cal"+column_name_list[1]])
    cal=cal.set_index(column_name_list[0])
    file_list=[]
    numbers_list=[]
    start_list = os.listdir(path)
    for d in start_list:
        if d.endswith(".csv"):
            file_list.append(d)
    for d in file_list:
        s = re.findall("\d+", d)
        try:
            numbers_list.append(int(s[0]))   #   !!!   change if main number isnīt first number in the file_name
        except:
            print(s)
    numbers_list = list(set(numbers_list))   #remove dublicates
    numbers_list.sort()

    def __init__(self, has, has_ref="REF"):
        self.list_contact=[]
        self.list_contact_ref=[]
        self.name=has
        self.name_ref=has+"_"+has_ref
        for aa in self.numbers_list:
            for bb in self.file_list:
                try:
                    if (str(aa) in bb)&(has in bb)&(len(bb)>9)&(is_int(int(bb[:len(str(aa))]))):
                        if has_ref not in bb:
                            self.list_contact.append(bb)
                        if has_ref in bb:
                            self.list_contact_ref.append(bb)
                except:
                    None

    def connect(self, header=44):
        list_to_csv=[]
        for csv_file in self.list_contact:
            list_to_csv.append(pd.read_csv(str(path+"/"+csv_file), header=header, names=[self.name+self.column_name_list[0], self.name+self.column_name_list[1]]))
        self.output = pd.concat(list_to_csv, axis=0)
        self.output = self.output.set_index(self.name+self.column_name_list[0])
        list_to_csv=[]
        for csv_file in self.list_contact_ref:
            list_to_csv.append(pd.read_csv(str(path+"/"+csv_file), header=header, names=[self.name_ref+self.column_name_list[0], self.name_ref+self.column_name_list[1]]))
        self.output_ref = pd.concat(list_to_csv, axis=0)
        self.output_ref = self.output_ref.set_index(self.name_ref+self.column_name_list[0])
        list_to_csv=[]
        self.output_all = pd.concat([self.output, self.output_ref], axis=1)
        self.output_all.index.name=self.column_name_list[0]
        self.output_all=self.output_all.merge(self.cal, how="outer", left_on=self.column_name_list[0], right_on=self.column_name_list[0])
        self.output_all=self.output_all.sort_index()
        self.output_all["cal"+self.column_name_list[1]]=self.output_all["cal"+self.column_name_list[1]].fillna(method='ffill')
        self.output_all["cal"+self.column_name_list[1]]=self.output_all["cal"+self.column_name_list[1]].fillna(method='backfill')
        self.output_all = self.output_all.dropna(subset=[self.name+self.column_name_list[1]])
        self.output_all[self.name+self.column_name_list[1]+"_corr"]=self.output_all[self.name+self.column_name_list[1]]+self.output_all["cal"+self.column_name_list[1]]
        self.output_all[self.name_ref+self.column_name_list[1]+"_corr"]=self.output_all[self.name_ref+self.column_name_list[1]]+self.output_all["cal"+self.column_name_list[1]]

def plotting_pag(data_list):
    writer = pd.ExcelWriter('output_pag.xlsx')          #PREPARE EXCEL
################################################   CREATE TAB AND PUT LIST TO EXCEL      ###############################
    for data_plot in data_list:

        ##########################   axis change as you want   ##########################
        name_y="Pow. (dBm)"
        name_x="Freq. (Mhz)"
        display_units='millions' #hundreds thousands ten_thousands hundred_thousands millions ten_millions hundred_millions billions trillions
        minor_unit_x=500000
        major_unit_x=500000
        minor_unit_y=5
        major_unit_y=5
        rotation=270
        ######################### end axis change as you want   #########################

        data_plot.output_all.to_excel(writer, data_plot.name)
        workbook = writer.book
        worksheet = writer.sheets[data_plot.name]
        plot = workbook.add_chart({'type': 'scatter', 'subtype': 'smooth'})
        plot.set_size({'width': 1920, 'height': 776})
        plot.add_series({'categories':[data_plot.name, 1, 0, data_plot.output_all.shape[0], 0], 'values':[data_plot.name, 1, 1, data_plot.output_all.shape[0], 1],'line':   {'width': 0.25}, 'name':data_plot.name })
        plot.add_series({'categories':[data_plot.name, 1, 0, data_plot.output_all.shape[0], 0], 'values':[data_plot.name, 1, 2, data_plot.output_all.shape[0], 2],'line':   {'width': 0.25}, 'name':data_plot.name_ref })
        plot.add_series({'categories':[data_plot.name, 1, 0, data_plot.output_all.shape[0], 0], 'values':[data_plot.name, 1, 4, data_plot.output_all.shape[0], 4],'line':   {'width': 0.25}, 'name':data_plot.name+"_corr" })
        plot.add_series({'categories':[data_plot.name, 1, 0, data_plot.output_all.shape[0], 0], 'values':[data_plot.name, 1, 5, data_plot.output_all.shape[0], 5],'line':   {'width': 0.25}, 'name':data_plot.name_ref+"corr" })
        min_x=round_down(data_plot.output_all.index.min(), -4)
        max_x=round_up(data_plot.output_all.index.max(), -4)
        min_y=round_down(min(list(data_plot.output_all.min())), -1)
        max_y=round_up(max(list(data_plot.output_all.max())), -1)
        # set axis
        plot.set_y_axis({"name": name_y, 'minor_unit': minor_unit_y,'major_unit': major_unit_y, 'crossing': str(min_y), "min": str(min_y), "max": str(max_y), 'major_gridlines': {'visible': True,'line': {'width': 0.25, 'dash_type': 'dash', 'color' : 'green'}}} )
        plot.set_x_axis({"name": name_x, 'display_units': display_units, 'minor_unit': minor_unit_x,'major_unit': major_unit_x,'num_font':  {'rotation': rotation}, "min": str(min_x), "max": str(max_x), 'crossing': "0", 'major_gridlines': {'visible': True,'line': {'width': 0.25, 'dash_type': 'dash', 'color' : 'red'}} })
    #write and save
        worksheet.insert_chart('P%d' %(3), plot)
    writer.save()

SPWA_nom=list_generator("SPWA_nom")
SPWA_nom.connect()
SPWA_red=list_generator("SPWA_red")
SPWA_red.connect()
SPWB_nom=list_generator("SPWB_nom")
SPWB_nom.connect()
SPWB_red=list_generator("SPWB_red")
SPWB_red.connect()

plotting_pag([SPWA_nom, SPWA_red, SPWB_red])


# coding=utf-8
# pylint: disable=too-many-lines
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union

from ... import _serialization

if TYPE_CHECKING:
    # pylint: disable=unused-import,ungrouped-imports
    from .. import models as _models

class AaaaRecord(_serialization.Model):
    """An AAAA record.

    :ivar ipv6_address: The IPv6 address of this AAAA record.
    :vartype ipv6_address: str
    """

    _attribute_map = {
        "ipv6_address": {"key": "ipv6Address", "type": "str"},
    }

    def __init__(self, *, ipv6_address: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword ipv6_address: The IPv6 address of this AAAA record.
        :paramtype ipv6_address: str
        """
        super().__init__(**kwargs)
        self.ipv6_address = ipv6_address

class ARecord(_serialization.Model):
    """An A record.

    :ivar ipv4_address: The IPv4 address of this A record.
    :vartype ipv4_address: str
    """

    _attribute_map = {
        "ipv4_address": {"key": "ipv4Address", "type": "str"},
    }

    def __init__(self, *, ipv4_address: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword ipv4_address: The IPv4 address of this A record.
        :paramtype ipv4_address: str
        """
        super().__init__(**kwargs)
        self.ipv4_address = ipv4_address

class CloudErrorBody(_serialization.Model):
    """An error response from the service.

    :ivar code: An identifier for the error. Codes are invariant and are intended to be consumed
     programmatically.
    :vartype code: str
    :ivar message: A message describing the error, intended to be suitable for display in a user
     interface.
    :vartype message: str
    :ivar target: The target of the particular error. For example, the name of the property in
     error.
    :vartype target: str
    :ivar details: A list of additional details about the error.
    :vartype details: list[~azure.mgmt.dns.v2016_04_01.models.CloudErrorBody]
    """

    _attribute_map = {
        "code": {"key": "code", "type": "str"},
        "message": {"key": "message", "type": "str"},
        "target": {"key": "target", "type": "str"},
        "details": {"key": "details", "type": "[CloudErrorBody]"},
    }

    def __init__(
        self,
        *,
        code: Optional[str] = None,
        message: Optional[str] = None,
        target: Optional[str] = None,
        details: Optional[List["_models.CloudErrorBody"]] = None,
        **kwargs: Any
    ) -> None:
        """
        :keyword code: An identifier for the error. Codes are invariant and are intended to be consumed
         programmatically.
        :paramtype code: str
        :keyword message: A message describing the error, intended to be suitable for display in a user
         interface.
        :paramtype message: str
        :keyword target: The target of the particular error. For example, the name of the property in
         error.
        :paramtype target: str
        :keyword details: A list of additional details about the error.
        :paramtype details: list[~azure.mgmt.dns.v2016_04_01.models.CloudErrorBody]
        """
        super().__init__(**kwargs)
        self.code = code
        self.message = message
        self.target = target
        self.details = details

class CnameRecord(_serialization.Model):
    """A CNAME record.

    :ivar cname: The canonical name for this CNAME record.
    :vartype cname: str
    """

    _attribute_map = {
        "cname": {"key": "cname", "type": "str"},
    }

    def __init__(self, *, cname: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword cname: The canonical name for this CNAME record.
        :paramtype cname: str
        """
        super().__init__(**kwargs)
        self.cname = cname

class MxRecord(_serialization.Model):
    """An MX record.

    :ivar preference: The preference value for this MX record.
    :vartype preference: int
    :ivar exchange: The domain name of the mail host for this MX record.
    :vartype exchange: str
    """

    _attribute_map = {
        "preference": {"key": "preference", "type": "int"},
        "exchange": {"key": "exchange", "type": "str"},
    }

    def __init__(self, *, preference: Optional[int] = None, exchange: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword preference: The preference value for this MX record.
        :paramtype preference: int
        :keyword exchange: The domain name of the mail host for this MX record.
        :paramtype exchange: str
        """
        super().__init__(**kwargs)
        self.preference = preference
        self.exchange = exchange

class NsRecord(_serialization.Model):
    """An NS record.

    :ivar nsdname: The name server name for this NS record.
    :vartype nsdname: str
    """

    _attribute_map = {
        "nsdname": {"key": "nsdname", "type": "str"},
    }

    def __init__(self, *, nsdname: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword nsdname: The name server name for this NS record.
        :paramtype nsdname: str
        """
        super().__init__(**kwargs)
        self.nsdname = nsdname

class PtrRecord(_serialization.Model):
    """A PTR record.

    :ivar ptrdname: The PTR target domain name for this PTR record.
    :vartype ptrdname: str
    """

    _attribute_map = {
        "ptrdname": {"key": "ptrdname", "type": "str"},
    }

    def __init__(self, *, ptrdname: Optional[str] = None, **kwargs: Any) -> None:
        """
        :keyword ptrdname: The PTR target domain name for this PTR record.
        :paramtype ptrdname: str
        """
        super().__init__(**kwargs)
        self.ptrdname = ptrdname

class RecordSet(_serialization.Model):  # pylint: disable=too-many-instance-attributes
    """Describes a DNS record set (a collection of DNS records with the same name and type).

    Variables are only populated by the server, and will be ignored when sending a request.

    :ivar id: The ID of the record set.
    :vartype id: str
    :ivar name: The name of the record set.
    :vartype name: str
    :ivar type: The type of the record set.
    :vartype type: str
    :ivar etag: The etag of the record set.
    :vartype etag: str
    :ivar metadata: The metadata attached to the record set.
    :vartype metadata: dict[str, str]
    :ivar ttl: The TTL (time-to-live) of the records in the record set.
    :vartype ttl: int
    :ivar fqdn: Fully qualified domain name of the record set.
    :vartype fqdn: str
    :ivar a_records: The list of A records in the record set.
    :vartype a_records: list[~azure.mgmt.dns.v2016_04_01.models.ARecord]
    :ivar aaaa_records: The list of AAAA records in the record set.
    :vartype aaaa_records: list[~azure.mgmt.dns.v2016_04_01.models.AaaaRecord]
    :ivar mx_records: The list of MX records in the record set.
    :vartype mx_records: list[~azure.mgmt.dns.v2016_04_01.models.MxRecord]
    :ivar ns_records: The list of NS records in the record set.
    :vartype ns_records: list[~azure.mgmt.dns.v2016_04_01.models.NsRecord]
    :ivar ptr_records: The list of PTR records in the record set.
    :vartype ptr_records: list[~azure.mgmt.dns.v2016_04_01.models.PtrRecord]
    :ivar srv_records: The list of SRV records in the record set.
    :vartype srv_records: list[~azure.mgmt.dns.v2016_04_01.models.SrvRecord]
    :ivar txt_records: The list of TXT records in the record set.
    :vartype txt_records: list[~azure.mgmt.dns.v2016_04_01.models.TxtRecord]
    :ivar cname_record: The CNAME record in the  record set.
    :vartype cname_record: ~azure.mgmt.dns.v2016_04_01.models.CnameRecord
    :ivar soa_record: The SOA record in the record set.
    :vartype soa_record: ~azure.mgmt.dns.v2016_04_01.models.SoaRecord
    """

    _validation = {
        "fqdn": {"readonly": True},
    }

    _attribute_map = {
        "id": {"key": "id", "type": "str"},
        "name": {"key": "name", "type": "str"},
        "type": {"key": "type", "type": "str"},
        "etag": {"key": "etag", "type": "str"},
        "metadata": {"key": "properties.metadata", "type": "{str}"},
        "ttl": {"key": "properties.TTL", "type": "int"},
        "fqdn": {"key": "properties.fqdn", "type": "str"},
        "a_records": {"key": "properties.ARecords", "type": "[ARecord]"},
        "aaaa_records": {"key": "properties.AAAARecords", "type": "[AaaaRecord]"},
        "mx_records": {"key": "properties.MXRecords", "type": "[MxRecord]"},
        "ns_records": {"key": "properties.NSRecords", "type": "[NsRecord]"},
        "ptr_records": {"key": "properties.PTRRecords", "type": "[PtrRecord]"},
        "srv_records": {"key": "properties.SRVRecords", "type": "[SrvRecord]"},
        "txt_records": {"key": "properties.TXTRecords", "type": "[TxtRecord]"},
        "cname_record": {"key": "properties.CNAMERecord", "type": "CnameRecord"},
        "soa_record": {"key": "properties.SOARecord", "type": "SoaRecord"},
    }

    def __init__(
        self,
        *,
        id: Optional[str] = None,  # pylint: disable=redefined-builtin
        name: Optional[str] = None,
        type: Optional[str] = None,
        etag: Optional[str] = None,
        metadata: Optional[Dict[str, str]] = None,
        ttl: Optional[int] = None,
        a_records: Optional[List["_models.ARecord"]] = None,
        aaaa_records: Optional[List["_models.AaaaRecord"]] = None,
        mx_records: Optional[List["_models.MxRecord"]] = None,
        ns_records: Optional[List["_models.NsRecord"]] = None,
        ptr_records: Optional[List["_models.PtrRecord"]] = None,
        srv_records: Optional[List["_models.SrvRecord"]] = None,
        txt_records: Optional[List["_models.TxtRecord"]] = None,
        cname_record: Optional["_models.CnameRecord"] = None,
        soa_record: Optional["_models.SoaRecord"] = None,
        **kwargs: Any
    ) -> None:
        """
        :keyword id: The ID of the record set.
        :paramtype id: str
        :keyword name: The name of the record set.
        :paramtype name: str
        :keyword type: The type of the record set.
        :paramtype type: str
        :keyword etag: The etag of the record set.
        :paramtype etag: str
        :keyword metadata: The metadata attached to the record set.
        :paramtype metadata: dict[str, str]
        :keyword ttl: The TTL (time-to-live) of the records in the record set.
        :paramtype ttl: int
        :keyword a_records: The list of A records in the record set.
        :paramtype a_records: list[~azure.mgmt.dns.v2016_04_01.models.ARecord]
        :keyword aaaa_records: The list of AAAA records in the record set.
        :paramtype aaaa_records: list[~azure.mgmt.dns.v2016_04_01.models.AaaaRecord]
        :keyword mx_records: The list of MX records in the record set.
        :paramtype mx_records: list[~azure.mgmt.dns.v2016_04_01.models.MxRecord]
        :keyword ns_records: The list of NS records in the record set.
        :paramtype ns_records: list[~azure.mgmt.dns.v2016_04_01.models.NsRecord]
        :keyword ptr_records: The list of PTR records in the record set.
        :paramtype ptr_records: list[~azure.mgmt.dns.v2016_04_01.models.PtrRecord]
        :keyword srv_records: The list of SRV records in the record set.
        :paramtype srv_records: list[~azure.mgmt.dns.v2016_04_01.models.SrvRecord]
        :keyword txt_records: The list of TXT records in the record set.
        :paramtype txt_records: list[~azure.mgmt.dns.v2016_04_01.models.TxtRecord]
        :keyword cname_record: The CNAME record in the  record set.
        :paramtype cname_record: ~azure.mgmt.dns.v2016_04_01.models.CnameRecord
        :keyword soa_record: The SOA record in the record set.
        :paramtype soa_record: ~azure.mgmt.dns.v2016_04_01.models.SoaRecord
        """
        super().__init__(**kwargs)
        self.id = id
        self.name = name
        self.type = type
        self.etag = etag
        self.metadata = metadata
        self.ttl = ttl
        self.fqdn = None
        self.a_records = a_records
        self.aaaa_records = aaaa_records
        self.mx_records = mx_records
        self.ns_records = ns_records
        self.ptr_records = ptr_records
        self.srv_records = srv_records
        self.txt_records = txt_records
        self.cname_record = cname_record
        self.soa_record = soa_record

class RecordSetListResult(_serialization.Model):
    """The response to a record set List operation.

    :ivar value: Information about the record sets in the response.
    :vartype value: list[~azure.mgmt.dns.v2016_04_01.models.RecordSet]
    :ivar next_link: The continuation token for the next page of results.
    :vartype next_link: str
    """

    _attribute_map = {
        "value": {"key": "value", "type": "[RecordSet]"},
        "next_link": {"key": "nextLink", "type": "str"},
    }

    def __init__(
        self, *, value: Optional[List["_models.RecordSet"]] = None, next_link: Optional[str] = None, **kwargs: Any
    ) -> None:
        """
        :keyword value: Information about the record sets in the response.
        :paramtype value: list[~azure.mgmt.dns.v2016_04_01.models.RecordSet]
        :keyword next_link: The continuation token for the next page of results.
        :paramtype next_link: str
        """
        super().__init__(**kwargs)
        self.value = value
        self.next_link = next_link

class RecordSetUpdateParameters(_serialization.Model):
    """Parameters supplied to update a record set.

    :ivar record_set: Specifies information about the record set being updated.
    :vartype record_set: ~azure.mgmt.dns.v2016_04_01.models.RecordSet
    """

    _attribute_map = {
        "record_set": {"key": "RecordSet", "type": "RecordSet"},
    }

    def __init__(self, *, record_set: Optional["_models.RecordSet"] = None, **kwargs: Any) -> None:
        """
        :keyword record_set: Specifies information about the record set being updated.
        :paramtype record_set: ~azure.mgmt.dns.v2016_04_01.models.RecordSet
        """
        super().__init__(**kwargs)
        self.record_set = record_set

class Resource(_serialization.Model):
    """Common fields that are returned in the response for all Azure Resource Manager resources.

    Variables are only populated by the server, and will be ignored when sending a request.

    :ivar id: Fully qualified resource ID for the resource. Ex -
     /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}.
    :vartype id: str
    :ivar name: The name of the resource.
    :vartype name: str
    :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or
     "Microsoft.Storage/storageAccounts".
    :vartype type: str
    """

    _validation = {
        "id": {"readonly": True},
        "name": {"readonly": True},
        "type": {"readonly": True},
    }

    _attribute_map = {
        "id": {"key": "id", "type": "str"},
        "name": {"key": "name", "type": "str"},
        "type": {"key": "type", "type": "str"},
    }

    def __init__(self, **kwargs: Any) -> None:
        """ """
        super().__init__(**kwargs)
        self.id = None
        self.name = None
        self.type = None

class SoaRecord(_serialization.Model):
    """An SOA record.

    :ivar host: The domain name of the authoritative name server for this SOA record.
    :vartype host: str
    :ivar email: The email contact for this SOA record.
    :vartype email: str
    :ivar serial_number: The serial number for this SOA record.
    :vartype serial_number: int
    :ivar refresh_time: The refresh value for this SOA record.
    :vartype refresh_time: int
    :ivar retry_time: The retry time for this SOA record.
    :vartype retry_time: int
    :ivar expire_time: The expire time for this SOA record.
    :vartype expire_time: int
    :ivar minimum_ttl: The minimum value for this SOA record. By convention this is used to
     determine the negative caching duration.
    :vartype minimum_ttl: int
    """

    _attribute_map = {
        "host": {"key": "host", "type": "str"},
        "email": {"key": "email", "type": "str"},
        "serial_number": {"key": "serialNumber", "type": "int"},
        "refresh_time": {"key": "refreshTime", "type": "int"},
        "retry_time": {"key": "retryTime", "type": "int"},
        "expire_time": {"key": "expireTime", "type": "int"},
        "minimum_ttl": {"key": "minimumTTL", "type": "int"},
    }

    def __init__(
        self,
        *,
        host: Optional[str] = None,
        email: Optional[str] = None,
        serial_number: Optional[int] = None,
        refresh_time: Optional[int] = None,
        retry_time: Optional[int] = None,
        expire_time: Optional[int] = None,
        minimum_ttl: Optional[int] = None,
        **kwargs: Any
    ) -> None:
        """
        :keyword host: The domain name of the authoritative name server for this SOA record.
        :paramtype host: str
        :keyword email: The email contact for this SOA record.
        :paramtype email: str
        :keyword serial_number: The serial number for this SOA record.
        :paramtype serial_number: int
        :keyword refresh_time: The refresh value for this SOA record.
        :paramtype refresh_time: int
        :keyword retry_time: The retry time for this SOA record.
        :paramtype retry_time: int
        :keyword expire_time: The expire time for this SOA record.
        :paramtype expire_time: int
        :keyword minimum_ttl: The minimum value for this SOA record. By convention this is used to
         determine the negative caching duration.
        :paramtype minimum_ttl: int
        """
        super().__init__(**kwargs)
        self.host = host
        self.email = email
        self.serial_number = serial_number
        self.refresh_time = refresh_time
        self.retry_time = retry_time
        self.expire_time = expire_time
        self.minimum_ttl = minimum_ttl

class SrvRecord(_serialization.Model):
    """An SRV record.

    :ivar priority: The priority value for this SRV record.
    :vartype priority: int
    :ivar weight: The weight value for this SRV record.
    :vartype weight: int
    :ivar port: The port value for this SRV record.
    :vartype port: int
    :ivar target: The target domain name for this SRV record.
    :vartype target: str
    """

    _attribute_map = {
        "priority": {"key": "priority", "type": "int"},
        "weight": {"key": "weight", "type": "int"},
        "port": {"key": "port", "type": "int"},
        "target": {"key": "target", "type": "str"},
    }

    def __init__(
        self,
        *,
        priority: Optional[int] = None,
        weight: Optional[int] = None,
        port: Optional[int] = None,
        target: Optional[str] = None,
        **kwargs: Any
    ) -> None:
        """
        :keyword priority: The priority value for this SRV record.
        :paramtype priority: int
        :keyword weight: The weight value for this SRV record.
        :paramtype weight: int
        :keyword port: The port value for this SRV record.
        :paramtype port: int
        :keyword target: The target domain name for this SRV record.
        :paramtype target: str
        """
        super().__init__(**kwargs)
        self.priority = priority
        self.weight = weight
        self.port = port
        self.target = target

class SubResource(_serialization.Model):
    """SubResource.

    :ivar id: Resource Id.
    :vartype id: str
    """

    _attribute_map = {
        "id": {"key": "id", "type": "str"},
    }

    def __init__(self, *, id: Optional[str] = None, **kwargs: Any) -> None:  # pylint: disable=redefined-builtin
        """
        :keyword id: Resource Id.
        :paramtype id: str
        """
        super().__init__(**kwargs)
        self.id = id

class TrackedResource(Resource):
    """The resource model definition for an Azure Resource Manager tracked top level resource which
    has 'tags' and a 'location'.

    Variables are only populated by the server, and will be ignored when sending a request.

    All required parameters must be populated in order to send to Azure.

    :ivar id: Fully qualified resource ID for the resource. Ex -
     /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}.
    :vartype id: str
    :ivar name: The name of the resource.
    :vartype name: str
    :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or
     "Microsoft.Storage/storageAccounts".
    :vartype type: str
    :ivar tags: Resource tags.
    :vartype tags: dict[str, str]
    :ivar location: The geo-location where the resource lives. Required.
    :vartype location: str
    """

    _validation = {
        "id": {"readonly": True},
        "name": {"readonly": True},
        "type": {"readonly": True},
        "location": {"required": True},
    }

    _attribute_map = {
        "id": {"key": "id", "type": "str"},
        "name": {"key": "name", "type": "str"},
        "type": {"key": "type", "type": "str"},
        "tags": {"key": "tags", "type": "{str}"},
        "location": {"key": "location", "type": "str"},
    }

    def __init__(self, *, location: str, tags: Optional[Dict[str, str]] = None, **kwargs: Any) -> None:
        """
        :keyword tags: Resource tags.
        :paramtype tags: dict[str, str]
        :keyword location: The geo-location where the resource lives. Required.
        :paramtype location: str
        """
        super().__init__(**kwargs)
        self.tags = tags
        self.location = location

class TxtRecord(_serialization.Model):
    """A TXT record.

    :ivar value: The text value of this TXT record.
    :vartype value: list[str]
    """

    _attribute_map = {
        "value": {"key": "value", "type": "[str]"},
    }

    def __init__(self, *, value: Optional[List[str]] = None, **kwargs: Any) -> None:
        """
        :keyword value: The text value of this TXT record.
        :paramtype value: list[str]
        """
        super().__init__(**kwargs)
        self.value = value

class Zone(TrackedResource):  # pylint: disable=too-many-instance-attributes
    """Describes a DNS zone.

    Variables are only populated by the server, and will be ignored when sending a request.

    All required parameters must be populated in order to send to Azure.

    :ivar id: Fully qualified resource ID for the resource. Ex -
     /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}.
    :vartype id: str
    :ivar name: The name of the resource.
    :vartype name: str
    :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or
     "Microsoft.Storage/storageAccounts".
    :vartype type: str
    :ivar tags: Resource tags.
    :vartype tags: dict[str, str]
    :ivar location: The geo-location where the resource lives. Required.
    :vartype location: str
    :ivar etag: The etag of the zone.
    :vartype etag: str
    :ivar max_number_of_record_sets: The maximum number of record sets that can be created in this
     DNS zone.  This is a read-only property and any attempt to set this value will be ignored.
    :vartype max_number_of_record_sets: int
    :ivar max_number_of_records_per_record_set: The maximum number of records per record set that
     can be created in this DNS zone.  This is a read-only property and any attempt to set this
     value will be ignored.
    :vartype max_number_of_records_per_record_set: int
    :ivar number_of_record_sets: The current number of record sets in this DNS zone.  This is a
     read-only property and any attempt to set this value will be ignored.
    :vartype number_of_record_sets: int
    :ivar name_servers: The name servers for this DNS zone. This is a read-only property and any
     attempt to set this value will be ignored.
    :vartype name_servers: list[str]
    :ivar zone_type: The type of this DNS zone (Public or Private). Known values are: "Public" and
     "Private".
    :vartype zone_type: str or ~azure.mgmt.dns.v2016_04_01.models.ZoneType
    """

    _validation = {
        "id": {"readonly": True},
        "name": {"readonly": True},
        "type": {"readonly": True},
        "location": {"required": True},
        "max_number_of_records_per_record_set": {"readonly": True},
        "name_servers": {"readonly": True},
    }

    _attribute_map = {
        "id": {"key": "id", "type": "str"},
        "name": {"key": "name", "type": "str"},
        "type": {"key": "type", "type": "str"},
        "tags": {"key": "tags", "type": "{str}"},
        "location": {"key": "location", "type": "str"},
        "etag": {"key": "etag", "type": "str"},
        "max_number_of_record_sets": {"key": "properties.maxNumberOfRecordSets", "type": "int"},
        "max_number_of_records_per_record_set": {"key": "properties.maxNumberOfRecordsPerRecordSet", "type": "int"},
        "number_of_record_sets": {"key": "properties.numberOfRecordSets", "type": "int"},
        "name_servers": {"key": "properties.nameServers", "type": "[str]"},
        "zone_type": {"key": "properties.zoneType", "type": "str"},
    }

    def __init__(
        self,
        *,
        location: str,
        tags: Optional[Dict[str, str]] = None,
        etag: Optional[str] = None,
        max_number_of_record_sets: Optional[int] = None,
        number_of_record_sets: Optional[int] = None,
        zone_type: Union[str, "_models.ZoneType"] = "Public",
        **kwargs: Any
    ) -> None:
        """
        :keyword tags: Resource tags.
        :paramtype tags: dict[str, str]
        :keyword location: The geo-location where the resource lives. Required.
        :paramtype location: str
        :keyword etag: The etag of the zone.
        :paramtype etag: str
        :keyword max_number_of_record_sets: The maximum number of record sets that can be created in
         this DNS zone.  This is a read-only property and any attempt to set this value will be ignored.
        :paramtype max_number_of_record_sets: int
        :keyword number_of_record_sets: The current number of record sets in this DNS zone.  This is a
         read-only property and any attempt to set this value will be ignored.
        :paramtype number_of_record_sets: int
        :keyword zone_type: The type of this DNS zone (Public or Private). Known values are: "Public"
         and "Private".
        :paramtype zone_type: str or ~azure.mgmt.dns.v2016_04_01.models.ZoneType
        """
        super().__init__(tags=tags, location=location, **kwargs)
        self.etag = etag
        self.max_number_of_record_sets = max_number_of_record_sets
        self.max_number_of_records_per_record_set = None
        self.number_of_record_sets = number_of_record_sets
        self.name_servers = None
        self.zone_type = zone_type

class ZoneDeleteResult(_serialization.Model):
    """The response to a Zone Delete operation.

    :ivar azure_async_operation: Users can perform a Get on Azure-AsyncOperation to get the status
     of their delete Zone operations.
    :vartype azure_async_operation: str
    :ivar status: Known values are: "InProgress", "Succeeded", and "Failed".
    :vartype status: str or ~azure.mgmt.dns.v2016_04_01.models.OperationStatus
    :ivar status_code: Known values are: "Continue", "SwitchingProtocols", "OK", "Created",
     "Accepted", "NonAuthoritativeInformation", "NoContent", "ResetContent", "PartialContent",
     "MultipleChoices", "Ambiguous", "MovedPermanently", "Moved", "Found", "Redirect", "SeeOther",
     "RedirectMethod", "NotModified", "UseProxy", "Unused", "TemporaryRedirect", "RedirectKeepVerb",
     "BadRequest", "Unauthorized", "PaymentRequired", "Forbidden", "NotFound", "MethodNotAllowed",
     "NotAcceptable", "ProxyAuthenticationRequired", "RequestTimeout", "Conflict", "Gone",
     "LengthRequired", "PreconditionFailed", "RequestEntityTooLarge", "RequestUriTooLong",
     "UnsupportedMediaType", "RequestedRangeNotSatisfiable", "ExpectationFailed", "UpgradeRequired",
     "InternalServerError", "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout",
     "HttpVersionNotSupported", and "Continue".
    :vartype status_code: str or ~azure.mgmt.dns.v2016_04_01.models.HttpStatusCode
    :ivar request_id:
    :vartype request_id: str
    """

    _attribute_map = {
        "azure_async_operation": {"key": "azureAsyncOperation", "type": "str"},
        "status": {"key": "status", "type": "str"},
        "status_code": {"key": "statusCode", "type": "str"},
        "request_id": {"key": "requestId", "type": "str"},
    }

    def __init__(
        self,
        *,
        azure_async_operation: Optional[str] = None,
        status: Optional[Union[str, "_models.OperationStatus"]] = None,
        status_code: Optional[Union[str, "_models.HttpStatusCode"]] = None,
        request_id: Optional[str] = None,
        **kwargs: Any
    ) -> None:
        """
        :keyword azure_async_operation: Users can perform a Get on Azure-AsyncOperation to get the
         status of their delete Zone operations.
        :paramtype azure_async_operation: str
        :keyword status: Known values are: "InProgress", "Succeeded", and "Failed".
        :paramtype status: str or ~azure.mgmt.dns.v2016_04_01.models.OperationStatus
        :keyword status_code: Known values are: "Continue", "SwitchingProtocols", "OK", "Created",
         "Accepted", "NonAuthoritativeInformation", "NoContent", "ResetContent", "PartialContent",
         "MultipleChoices", "Ambiguous", "MovedPermanently", "Moved", "Found", "Redirect", "SeeOther",
         "RedirectMethod", "NotModified", "UseProxy", "Unused", "TemporaryRedirect", "RedirectKeepVerb",
         "BadRequest", "Unauthorized", "PaymentRequired", "Forbidden", "NotFound", "MethodNotAllowed",
         "NotAcceptable", "ProxyAuthenticationRequired", "RequestTimeout", "Conflict", "Gone",
         "LengthRequired", "PreconditionFailed", "RequestEntityTooLarge", "RequestUriTooLong",
         "UnsupportedMediaType", "RequestedRangeNotSatisfiable", "ExpectationFailed", "UpgradeRequired",
         "InternalServerError", "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout",
         "HttpVersionNotSupported", and "Continue".
        :paramtype status_code: str or ~azure.mgmt.dns.v2016_04_01.models.HttpStatusCode
        :keyword request_id:
        :paramtype request_id: str
        """
        super().__init__(**kwargs)
        self.azure_async_operation = azure_async_operation
        self.status = status
        self.status_code = status_code
        self.request_id = request_id

class ZoneListResult(_serialization.Model):
    """The response to a Zone List or ListAll operation.

    :ivar value: Information about the DNS zones.
    :vartype value: list[~azure.mgmt.dns.v2016_04_01.models.Zone]
    :ivar next_link: The continuation token for the next page of results.
    :vartype next_link: str
    """

    _attribute_map = {
        "value": {"key": "value", "type": "[Zone]"},
        "next_link": {"key": "nextLink", "type": "str"},
    }

    def __init__(
        self, *, value: Optional[List["_models.Zone"]] = None, next_link: Optional[str] = None, **kwargs: Any
    ) -> None:
        """
        :keyword value: Information about the DNS zones.
        :paramtype value: list[~azure.mgmt.dns.v2016_04_01.models.Zone]
        :keyword next_link: The continuation token for the next page of results.
        :paramtype next_link: str
        """
        super().__init__(**kwargs)
        self.value = value
        self.next_link = next_link


from sierra.base_parameters import BaseParameter

from sierra.utilities.converter import convert

class SFPUC_requirement_Demand(BaseParameter):
    """"""

    def _value(self, timestep, scenario_index):

        # Assume 265 MGD = 366.4 MCM/year
        annual_demand_mcm = self.model.parameters["SFPUC requirement/Annual Demand"].value(timestep, scenario_index)

        week = min(timestep.datetime.week, 52)
        daily_fractions = self.model.tables["SFPUC weekly fraction"]
        daily_fraction = daily_fractions[week] / 7
        daily_demand_cms = annual_demand_mcm * daily_fraction / 0.0864

        hh = self.model.nodes["Hetch Hetchy Reservoir"].volume[scenario_index.global_id]
        if hh <= 200:
            demand_reduction = 0.3
            daily_demand_cms *= (1 - demand_reduction)
        else:
            demand_reduction = self.model.parameters["SFPUC requirement/Demand Reduction"].get_value(scenario_index)
            daily_demand_cms *= (1 + demand_reduction / 2)

        return daily_demand_cms

    def value(self, timestep, scenario_index):
        try:
            return convert(self._value(timestep, scenario_index), "m^3 s^-1", "m^3 day^-1", scale_in=1,
                           scale_out=1000000)
        except Exception as err:
            print('ERROR for parameter {}'.format(self.name))
            print('File where error occurred: {}'.format(__file__))
            print(err)
            raise

    @classmethod
    def load(cls, model, data):
        try:
            return cls(model, **data)
        except Exception as err:
            print('File where error occurred: {}'.format(__file__))
            print(err)
            raise

SFPUC_requirement_Demand.register()


from django.urls import path
from . import news_view
from . import views

app_name = 'woquApp'

urlpatterns = [
    path('',news_view.index, name = 'index'),
    path("login/",views.login,name="login"),   #登录功能
    path('up_news/', news_view.up_news, name='up_news'),  # 发表动态
    path('news/', news_view.news, name='news'),  # 动态
    path('send/',views.send,name='send'),   # 点赞
    path('back/',views.back,name='back'),   # 撤回赞
    path('register/',views.register,name="register"),
    path('register1/',views.register1,name="register1"),
    path('detail/',views.detail,name="detail"),
    path('chat/',views.chat,name="chat"),
    path('zhuye/',views.zhuye,name="zhuye"),
    path('interest/',views.interest,name="interest"),
    path('comment/<nid>',views.comment,name="comment"),

]


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

from django.db import models, migrations

class Migration(migrations.Migration):

    dependencies = [
        ('reports', '0002_report_county'),
        ('users', '0002_auto_20150730_1458'),
    ]

    operations = [
        migrations.CreateModel(
            name='Notification',
            fields=[
                ('notification_id', models.AutoField(serialize=False, primary_key=True)),
                ('created_on', models.DateTimeField(auto_now_add=True)),
                ('report', models.ForeignKey(to='reports.Report')),
                ('user', models.ForeignKey(to='users.User')),
            ],
            options={
                'db_table': 'notification',
            },
        ),
        migrations.CreateModel(
            name='UserNotificationQuery',
            fields=[
                ('user_notification_query_id', models.AutoField(serialize=False, primary_key=True)),
                ('query', models.TextField(help_text='A JSON encoded set of POST parameters to pass to the ReportSearchForm that match reports the user should be notified about')),
                ('user', models.ForeignKey(to='users.User')),
            ],
            options={
                'db_table': 'user_notification_query',
            },
        ),
    ]


import sys
import os
import cv2 as cv
import numpy as np
from enum import Enum

class Mode(Enum):
  PREVIEW = 0
  CUSTOM = 1
  CANNY = 2
  BLUR = 3
  COLOR_SPACE = 4
  TRANSFORM = 5
  THRESHOLD = 6
  FILTERING = 7
  WATERSHED = 8
  FEATURE = 9
  CURVED = 10
  CONTRAST = 11

class FunctionHandler:
  def __init__(self, mode=Mode.PREVIEW):
    # attributes for saving screenshot
    self.save = False
    self.dest = os.path.abspath('.')

    # tracks current status
    self.mode = mode
    self.alive = True

  def select_function(self):
    key = cv.waitKey(1)
    if key == ord('q') or key == 27:
      self.alive = False
    elif key == ord('s'):
      self.save = True
    elif key == ord('w'):
      self.mode = Mode.PREVIEW
    elif key == ord('a'):
      self.mode = Mode.CUSTOM
    elif key == ord('c'):
      self.mode = Mode.CANNY
    elif key == ord('e'):
      self.mode = Mode.BLUR
    elif key == ord('r'):
      self.mode = Mode.COLOR_SPACE
    elif key == ord('t'):
      self.mode = Mode.TRANSFORM
    elif key == ord('y'):
      self.mode = Mode.THRESHOLD
    elif key == ord('u'):
      self.mode = Mode.FILTERING
    elif key == ord('i'):
      self.mode = Mode.WATERSHED
    elif key == ord('o'):
      self.mode = Mode.FEATURE
    elif key == ord('p'):
      self.mode = Mode.CURVED
    elif key == ord('d'):
      self.mode = Mode.CONTRAST

  def process(self, frame):
    if self.mode == Mode.PREVIEW:
      frame = frame
    elif self.mode == Mode.CUSTOM:
      # kernels
      kernel1 = np.ones((15,15), np.uint8)
      kernel2 = np.ones((5,5), np.uint8)

      # convert
      frame = self.color_space(frame)
      frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

      # thresholding, morphological transformations
      ret, frame = cv.threshold(frame, 0, 255, cv.THRESH_BINARY+cv.THRESH_OTSU)
      #frame = cv.morphologyEx(frame, cv.MORPH_CLOSE, kernel1)
      #frame = cv.morphologyEx(frame, cv.MORPH_OPEN, kernel2)
      #frame = cv.erode(frame, kernel2, iterations=1)

      x, y, w, h = cv.boundingRect(frame)

      # contour properties
      try:
        left = (x, np.argmax(frame[:,x]))
        right = (x+w-1, np.argmax(frame[:,x+w-1]))
        top = (np.argmax(frame[y,:]), y)
        bottom = (np.argmax(frame[y+hj-1,:]), y+h-1)

        cv.circle(frame, left, 4, (0, 50, 255), 2)
        cv.circle(frame, right, 4, (0, 255, 255), -1)
        cv.circle(frame, top, 4, (255, 50, 0), -1)
        cv.circle(frame, bottom, 4, (255, 255, 0), -1)
      except Exception as e:
        pass

    elif self.mode == Mode.CANNY:
      frame = cv.Canny(frame, 100, 150)
    elif self.mode == Mode.BLUR:
      frame = cv.blur(frame, (13, 13))
    elif self.mode == Mode.COLOR_SPACE:
      frame = self.color_space(frame)
    elif self.mode == Mode.TRANSFORM:
      frame = cv.resize(frame, None, fx=8, fy=8, interpolation=cv.INTER_CUBIC)
    elif self.mode == Mode.THRESHOLD:
      gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
      #ret, frame = cv.threshold(frame, 127, 255, cv.THRESH_BINARY)
      #frame = cv.adaptiveThreshold(frame, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 11, 2)
      #frame = cv.adaptiveThreshold(frame, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 11, 2)
      ret, frame = cv.threshold(gray, 0, 255, cv.THRESH_BINARY+cv.THRESH_OTSU)
    elif self.mode == Mode.FILTERING:
      #frame = cv.medianBlur(frame, 5)
      frame = cv.bilateralFilter(frame, 9, 75, 75)
    elif self.mode == Mode.WATERSHED:
      frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
      ret, frame = cv.threshold(frame, 0, 255, cv.THRESH_BINARY_INV+cv.THRESH_OTSU)
    elif self.mode == Mode.FEATURE:
      gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
      sift = cv.SIFT_create()
      kp = sift.detect(gray, None)
      frame = cv.drawKeypoints(gray, kp, frame)
    elif self.mode == Mode.CURVED:
      frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
      edges = cv.Canny(frame, 150, 200, apertureSize=3)
      min_line_len = 1
      max_line_gap = 1
      lines = cv.HoughLinesP(edges, cv.HOUGH_PROBABILISTIC, np.pi/180, 90, min_line_len, min_line_len, max_line_gap)
      for x in range(0, len(lines)):
        for x1, y1, x2, y2 in lines[x]:
          pts = np.array([[x1, y1], [x2, y2]], np.int32)
          cv.polylines(frame, [pts], True, (0, 255, 0))

    elif self.mode == Mode.CONTRAST:
      frame = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
      contrast = 2
      brightness = 1
      frame[:,:,2] = np.clip(contrast*frame[:,:,2]+brightness, 0, 255)
      frame = cv.cvtColor(frame, cv.COLOR_HSV2BGR)
      cv.normalize(frame, frame, 0, 255, cv.NORM_MINMAX)

    # log current mode to terminal
    print(self.mode.name)

    if self.save:
      self.save = False
      cv.imwrite(f'{self.dest}/frame.jpg', frame)
    return frame

  def color_space(self, frame):
    # convert frame from BGR to HSV
    hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)

    # define range of blue color in HSV
    lower = np.array([0, 100, 100])
    upper = np.array([10, 255, 255])

    # threshold the HSV frame to get only blue colors
    mask = cv.inRange(hsv, lower, upper)
    res = cv.bitwise_and(frame, frame, mask=mask)
    return res

def main():
  s = 0
  if len(sys.argv) > 1:
    s = sys.argv[1]

  source = cv.VideoCapture(s)

  win_name = 'Camera'
  cv.namedWindow(win_name, cv.WINDOW_NORMAL)

  fh = FunctionHandler()
  alive = True
  mode = Mode.PREVIEW

  while fh.alive:
    has_frame, frame = source.read()
    if not has_frame:
      break

    # image manipulation
    mode = fh.select_function()
    frame = fh.process(frame)

    # display image
    cv.imshow(win_name, frame)

  source.release()
  cv.destroyWindow(win_name)

if __name__ == '__main__':
  main()


# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import os
import sys
import pandas

class transaction_scanner_firstrade_csv:
    def __init__(self):
        self.src_columns = [
            "Symbol"
            , "Quantity"
            , "Price"
            , "Action"
            , "Description"
            , "TradeDate"
            , "SettledDate"
            , "Interest"
            , "Amount"
            , "Commission"
            , "Fee"
            , "CUSIP"
            , "RecordType"]

        self.tgt_columns_1099 = [
            "Symbol"
            , "Description"
            , "Quantity"
            , "Date Acquired"
            , "Date Sold"
            , "Sales Proceeds"
            , "Cost"
            , "Total Gain / Loss "
            , "% Gain / Loss"]
        self.src_csv_path = ""
        self.dic_stocks_to_transaction = {}

    def import_csv(self, path):
        self.src_csv_path = path
        csv_data_frame = pandas.read_csv(path)
        for key, item in csv_data_frame.iterrows():
            if item["Symbol"] not in self.dic_stocks_to_transaction:
                self.dic_stocks_to_transaction[item["Symbol"]] = []
            self.dic_stocks_to_transaction[item["Symbol"]].append(item)

    def build_1099(self):
        self.all_tax_events = []
        for key, ticker_transactions in self.dic_stocks_to_transaction.items():
            ticker_buy_transactions = []
            for i in range(0, len(ticker_transactions)):
                transaction = ticker_transactions[i]
                if(transaction["Action"]=="BUY"):
                    ticker_buy_transactions.append(transaction)
                    #if transaction["Symbol"].strip() == "BND":
                    #    print(transaction.to_list())
                elif (transaction["Action"]=="SELL"):
                    #if transaction["Symbol"].strip() == "BND":
                    #    print(transaction.to_list())
                    tax_event_hdr = [transaction["Symbol"]]
                    tax_event_hdr = tax_event_hdr + [transaction["Description"]]
                    if(len(ticker_buy_transactions) == 0):
                        print(f"empty buy list for {transaction['Symbol']} at {transaction['TradeDate']}")
                    sales_proceeds = 0
                    to_sell = abs(int(float(transaction["Quantity"])))
                    to_pop = 0
                    for buy_event in ticker_buy_transactions:
                        if to_sell == 0:
                            break;
                        bought = float(buy_event["Quantity"])
                        if to_sell >= bought:
                            sell_amount = bought
                            to_sell -= bought
                            to_pop += 1
                        else:
                            sell_amount = to_sell
                            buy_event["Quantity"]=bought-sell_amount
                            to_sell = 0

                        tax_event = tax_event_hdr
                        tax_event = tax_event + [buy_event["Quantity"]]  # Quantity column
                        tax_event = tax_event + [buy_event["TradeDate"]]  # "Date Acquired" column
                        tax_event = tax_event + [transaction["TradeDate"]]  # "Date Sold" column
                        sales_sroceeds = int(sell_amount)*float(transaction["Price"])
                        tax_event = tax_event + [str(sales_sroceeds)]  # "Sales Proceeds" column
                        cost = int(sell_amount)*float(buy_event["Price"])
                        tax_event = tax_event + [str(cost)]  # "Sales Proceeds" column
                        tax_event = tax_event + [f"{sales_sroceeds-cost}"]  # "Total Gain / Loss" column

                        if(cost != 0):
                            prcnt = (sales_sroceeds-cost)/cost
                        else:
                            prcnt = 0
                        tax_event = tax_event + [f"{prcnt*100}"]  # "% Gain / Loss" column
                        self.all_tax_events.append(tax_event)
                    for i in range(0,to_pop):
                        ticker_buy_transactions.pop(0)
        tax_df = pandas.DataFrame(self.all_tax_events, columns=self.tgt_columns_1099)
        tax_df.to_csv("1099.csv")

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    ts = transaction_scanner_firstrade_csv()
    ts.import_csv("FT_CSV_63856457_2021_01_09.csv")
    ts.build_1099()
    print("done")

# See PyCharm help at https://www.jetbrains.com/help/pycharm/


import pygame
import random
import math
from pygame.locals import *
from general_functions import *

class RenderText(pygame.sprite.Sprite):
    pos = None
    pos_rel = None

    def __init__(self, screen, text='text', pos=(0, 0), pos_rel=(LEFT, TOP),
                 font=None, size=20, color=(255, 255, 255), antialias=True):
        """Inicializa Sprite de texto"""
        pygame.sprite.Sprite.__init__(self)
        self.font = pygame.font.Font(font, size)    # Tamaño del texto
        self.color = color  # Color de la fuente
        self.text = text    # Texto a mostrar
        self.pos = pos  # Posición del texto
        self.pos_rel = pos_rel  # Posición relativa con respecto a la pantalla
        self.screen = screen    # Screen en donde se va a hacer el render del texto
        self.antialias = antialias

        self.rerender() # Prepara el render del texto

    def update(self):
        pass

    def calculate_position(self):
        """Calcula la posición real en función de la posición relativa"""
        return (
            self.pos_rel[0]*(self.screen.get_size()[0]/2 - self.rect.width/2)
            + (1-2*(self.pos_rel[0]/2))*self.pos[0],
            self.pos_rel[1]*(self.screen.get_size()[1]/2 - self.rect.height/2)
            + (1-2*(self.pos_rel[1]/2))*self.pos[1],
            )

    def print_text(self, text, pos=None):
        """Actualiza el texto con los datos y se asigna locación para mostrarlos"""
        self.text = text
        if pos:
            self.pos = pos
        self.rerender(pos)

    def rerender(self, pos = None):
        """Prepara el render del texto"""
        self.image = self.font.render(self.text, self.antialias, self.color)
        self.rect = self.image.get_rect()
        # Si se pasa locación, renderea ahí
        if pos:
            self.rect.x, self.rect.y = pos[0], pos[1]

        # Si no se pasa locación, renderealo en la esquina inferior derecha
        else:
            self.rect.x, self.rect.y = self.calculate_position()


# Expression trees from Wednesday class
import sys
sys.path.insert(0, "../lib")

from structviz import StructViz
from valuetree import *

if False:
    t0 = ValueTree(42)
    StructViz.update_viz(t0, "t", pause=-1)

    t0 = ValueTree(99,  [ ValueTree(42, [ValueTree(3)]), ValueTree(88) ] )
    StructViz.update_viz(t0, "t", pause=-1)

    t0 = ValueTree('+',  [
        ValueTree('/', [ValueTree(3), ValueTree(4)]),
        ValueTree(88) ] )
    StructViz.update_viz(t0, "t", pause=-1)

    t1 = ValueTree("Bad", [t0, t0])
    StructViz.update_viz(t1, "t", pause=-1)

# special cases

if True:
    print("Constructing tree from list")
    t0 = ValueTree.list_to_tree([ [], 1, 2, 3, [4, 5, [ [], []]], [ [ 6, 7]]])

    # t0 = ValueTree.list_to_tree([1, [43, [2, 21]], 3])
    StructViz.update_viz(t0, "t", pause=-1)

    s0 = t0.get_shape()
    print("Shape of t0:", s0)
    t1 = ValueTree.list_to_tree(s0)
    s1 = t1.get_shape()
    if s0 == s1:
        print("Shapes match: {}".format(s0))
    else:
        print("Shapes differ:\n{}\n{}".format(s0, s1))

if True:
    print("Making a structural copy")
    s = [[],[ [], [] ]]
    t_orig = ValueTree.list_to_tree(s)
    t_copy = t_orig.list_to_tree(t_orig.get_shape())
    StructViz.update_viz([t_orig, t_copy], "t", pause=-1)

if False:
    t0 = ValueTree('*', [
            ValueTree('+', [ValueTree(3), ValueTree(4)]),
            ValueTree('+', [ValueTree(7), ValueTree(11)])
            ])

    print("Doing pre-order")
    t0.pre_order(print)

if False:

    print("Visualizing post-order")
    StructViz.update_viz(t0, "t-init", pause=-1)
    cursor = None
    def action(n):
        cursor = n
        StructViz.update_viz({'c':cursor}, "t", pause=-1)
    t0.post_order(action)


from instagram import WebAgentAccount, Account
from time import sleep
from random import randint
import csv
import os

BASE_URL = 'https://www.instagram.com/'
BASE_USER = 'pavelvolyaofficial'
agent = WebAgentAccount('make_dreamscome_true')
agent.auth('python2323')

all_users = []

def get_account(user):
    return Account(user)

def get_followers(user):
    agent.update(user)
    followers = agent.get_followers(user)
    followers = list(map(lambda acc: str(acc), followers[0]))
    global all_users
    all_users += followers

def get_info_about_user(user):
    user_info = {}

    following_count = user.follows_count
    media_count = user.media_count
    account_owner = user.full_name
    followers_count = user.followers_count
    account_url = BASE_URL + user.username

    user_info['account_owner'] = account_owner
    user_info['followers_count'] = followers_count
    user_info['media_count'] = media_count
    user_info['following_count'] = following_count
    user_info['account_url'] = account_url

    print(user_info)
    return user_info

def save_to_csv(item):
    if os.path.exists('data/insta_users.csv'):
        with open('data/insta_users.csv', 'a') as file:
            writer = csv.writer(file)
            values = tuple(item.values())
            writer.writerow(values)
    else:
        with open('data/insta_users.csv', 'a') as file:
            writer = csv.writer(file)
            keys = tuple(item.keys())
            values = tuple(item.values())
            writer.writerow(keys)
            writer.writerow(values)

def action_over_user(user):
    user = get_account(user)
    get_followers(user)
    user_info = get_info_about_user(user)
    save_to_csv(user_info)
    sleep(randint(1, 3))

def main():
    followers = action_over_user(BASE_USER)
    for user in all_users:
        action_over_user(user)

if __name__ == '__main__':
    main()


import keras.layers
import numpy as np
import random
import string
import tensorflow as tf
from .common import random_string

def convert_upsample_bilinear(params, w_name, scope_name, inputs, layers, weights, names):
    """
    Convert upsample_bilinear2d layer.

    Args:
        params: dictionary with layer parameters
        w_name: name prefix in state_dict
        scope_name: pytorch scope name
        inputs: pytorch node inputs
        layers: dictionary with keras tensors
        weights: pytorch state_dict
        names: use short names for keras layers
    """
    print('Converting upsample...')

    if names == 'short':
        tf_name = 'UPSL' + random_string(4)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    output_size = params.get('output_size', layers.get(inputs[1] + '_np'))
    align_corners = params.get('align_corners', 1) > 0

    def target_layer(x, size=output_size, align_corners=align_corners, data_format='channels_first'):
        import tensorflow as tf
        if data_format == 'channels_first':
            x = tf.transpose(x, [0, 2, 3, 1])
        x = tf.image.resize_images(x, size, align_corners=align_corners)
        if data_format == 'channels_first':
            x = tf.transpose(x, [0, 3, 1, 2])
        return x

    lambda_layer = keras.layers.Lambda(target_layer)
    layers[scope_name] = lambda_layer(layers[inputs[0]])

def convert_upsample(params, w_name, scope_name, inputs, layers, weights, names):
    """
    Convert nearest upsampling layer.

    Args:
        params: dictionary with layer parameters
        w_name: name prefix in state_dict
        scope_name: pytorch scope name
        inputs: pytorch node inputs
        layers: dictionary with keras tensors
        weights: pytorch state_dict
        names: use short names for keras layers
    """
    print('Converting upsample...')

    if params['mode'] != 'nearest':
        raise AssertionError('Cannot convert non-nearest upsampling')

    if names == 'short':
        tf_name = 'UPSL' + random_string(4)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    if 'height_scale' in params and 'width_scale' in params:
        scale = (params['height_scale'], params['width_scale'])
    else:
        scale = layers[inputs[1] + '_np'][-2:]
    upsampling = keras.layers.UpSampling2D(size=scale, name=tf_name, interpolation='nearest')
    layers[scope_name] = upsampling(layers[inputs[0]])


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

import webapp2
from google.appengine.api import urlfetch
import json
import jinja2

networkJson = urlfetch.fetch("https://tokyo.fantasy-transit.appspot.com/net?format=json").content  # ウェブサイトから電車の線路情報をJSON形式でダウンロードする
network = json.loads(networkJson.decode('utf-8'))  # JSONとしてパースする（stringからdictのlistに変換する）

tmpl = jinja2.Template(  # Jinjaのテンプレートエンジンを使ってHTMLを作ります
    u'''
こういう線路があります：

{% for line in network %}

 {{line["Name"]}}

    {% for station in line["Stations"] %}

 {{station}}

    {% endfor %}

{% endfor %}

''')

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
        self.response.write(tmpl.render(network=network))

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)


from typing import Any, List, Callable
from threading import Timer, Thread
from collections import OrderedDict
from pathlib import Path
import socket
import re
import secrets
import logging
import platform
import traceback

RE_PARSE_PRIVMSG = r"^:(?P<owner>\w+)!.+PRIVMSG\s+#(?P<channel>\w+)\s+:\$(?P<commandstr>.+)"
RE_PARSE_COMMADSET = r"(?P<command>\w+)\s*(?P<args>.*)"

logging.basicConfig(level=logging.DEBUG)

def send_bytes(string: str, encoding: str = "utf-8") -> bytes:
    return bytes(string, encoding)

class RepeatedTimer(object):
    def __init__(self, interval, function, *args, **kwargs):
        self._timer = None
        self.interval = interval
        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.is_running = False
        self.start()

    def _run(self):
        self.is_running = False
        self.start()
        self.function(*self.args, **self.kwargs)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self._timer.start()
            self.is_running = True

    def stop(self):
        self._timer.cancel()
        self.is_running = False

class Bot:
    sock: socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def __init__(self, host: str = "chat.freenode.net", port: int = 6667, channel: str = "#slavebotpool666", boss_name="bos666", bot_prefix: str = 'SLAVEBOT', bot_type='Undefined'):
        self.host = host
        self.port = port
        self.channel = channel
        self.boss_name = boss_name
        self.bot_prefix = bot_prefix
        self.bot_type = bot_type
        self.bot_id = secrets.token_hex(3)
        self.bot_fullname = f"{self.bot_prefix}_{self.bot_id}"
        self.SERVER_STATUS = True
        self.COMMAND_SET = dict()
        self.ping_timer: RepeatedTimer = None
        self.ROOT_PATH = Path("~").expanduser()

    def use_other_bot_commands(self, other_bot:Any) -> None:
        self.COMMAND_SET.update(other_bot.COMMAND_SET)

    def read_config_from_dict(self, config: dict) -> None:
        for key, value in config.items():
            setattr(self, key, value)

    def _revc(self, bufsize: int = 2024) -> str:
        return self.sock.recv(bufsize).decode("utf-8").strip('\n\r')

    def join_channel(self):
        self.sock.send(send_bytes(f"JOIN {self.channel}\n"))

    def send_text_thread(self, text: str):
        def thread_send(text):
            self.sock.send(send_bytes(f"PRIVMSG {self.channel} :{line}\n"))
        for line in text.split('\n'):
            th = Thread(target=thread_send, args=(line,))
            th.start()

        del th

    def send_text(self, text: str):
        for line in text.split('\n'):
            self.sock.send(send_bytes(f"PRIVMSG {self.channel} :{line}\n"))

    def pong(self):
        self.send_text("**Im alive**")

    def exit_server(self):
        self.sock.send(send_bytes("QUIT \n"))
        self.sock.close()
        self.ping_timer.stop()
        self.SERVER_STATUS = False

    def execute(self, func_dict, args: List[str]):
        if func_dict['all'] and args[0] == '/all':
            func_dict['func'](bot=self, args=args)
        if self.bot_id == args[0]:
            func_dict['func'](bot=self, args=args)

    def parse_command(self, raw_data: bytes):
        msg_match = re.match(RE_PARSE_PRIVMSG, raw_data)
        if msg_match:
            owner = msg_match.group('owner')
            commandstr = msg_match.group('commandstr')
            if owner == self.boss_name:
                cmd_match = re.match(RE_PARSE_COMMADSET, commandstr)
                if cmd_match:
                    command = cmd_match.group('command')
                    args = cmd_match.group('args').split(' ')

                    st = self.COMMAND_SET.get(command, None)
                    if st is not None:
                        self.execute(st, args)
                    else:
                        self.send_text(f"Command not found")
                        logging.error("Commmand not found")
                else:
                    logging.error("Regex error - cmd_parser")
            else:
                #logging.error("Regex error - privmsg")
                pass

    def listen_forever(self) -> None:
        while self.SERVER_STATUS:
            raw_data = self._revc()
            logging.debug(raw_data)
            self.parse_command(raw_data)

    def connect(self) -> None:
        self.sock.connect((self.host, self.port))
        self.sock.send(send_bytes(
            f"USER {self.bot_fullname} {self.bot_fullname} {self.bot_fullname} {self.bot_fullname}\n"))
        self.sock.send(send_bytes(f"NICK {self.bot_fullname}\n"))
        self.join_channel()
        logging.debug(f"Connected {self.host}")

    def send_command_help(self) -> None:
        for cmdstr, cmd_stuff in OrderedDict(sorted(self.COMMAND_SET.items(), key=lambda x: x[0])).items():
            self.send_text(f"{cmdstr}: {cmd_stuff['help_text']}")

    def connected_afer(self):
        self.send_command_help()
        for cmdstr, cmd_stuff in self.COMMAND_SET.items():
            if cmd_stuff['on_connect'] == True:
                cmd_stuff['func'](bot=self)

        self.ping_timer = RepeatedTimer(60, self.pong)

    def _panic(self):
        self.exit_server()
        self.start()

    def start(self, safe=False):
        if safe:
            try:
                self.connect()
                self.connected_afer()
                self.listen_forever()
            except Exception as e:
                self.send_text_thread(traceback.format_exc())
                self.send_text_thread("Apparently this command is incorrect. If you can't fix it, don't use it again")
                self.listen_forever()
        else:
            self.connect()
            self.connected_afer()
            self.listen_forever()

    def register(self, cmdstr, all=False, on_connect=False, help_text="No description given"):
        def wrap_register(func):
            self.COMMAND_SET[cmdstr] = {
                'all': all, 'on_connect': on_connect, 'help_text': help_text, 'func': func}
            return func
        return wrap_register


# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def sortedListToBST(self, head):
        """
        :type head: ListNode
        :rtype: TreeNode
        """
        # tmp = []
        # while head:
        #     tmp.append(head.val)
        #     head = head.next
        # def f(nums):
        #     if not nums: return None
        #     mid = len(nums)//2
        #     tmp = TreeNode(nums[mid])
        #     tmp.left = f(nums[:mid])
        #     tmp.right = f(nums[mid+1:])
        #     return tmp
        # return f(tmp)

        # two pointer

        def Helper(start, end):
            if start > end: return None
            middle = (start + end) // 2
            left = Helper(start, middle-1)
            parent = TreeNode(self.node.val)
            parent.left = left
            self.node = self.node.next
            parent.right = Helper(middle+1, end)
            return parent
        current, length = head, 0
        while current:
            current = current.next
            length += 1
        self.node = head
        return Helper(0, length-1)

Algorithms/Convert Sorted List to Binary Search Tree/Convert Sorted List to Binary Search Tree.py


from datamanager import DataManager
from indicators import Ichimoku, RSI, StochasticRSI

class Timeframe:
    """Holds actual price data and manages the indicators on that data"""

    def __init__(self, pair, timeframe):
        self.dm = DataManager()
        self.data = self.dm.open(pair, timeframe)
        self.rsi = None
        self.stochrsi = None
        self.ichimoku = None

    def run_indicators(self, rsi, stochrsi, ichimoku):
        """
        Just because you created the Timeframe, doesn't mean
        you should run all the indicatros straight away!
        On the other hand, accumulating lots of Coins hanging around,
        waiting for you to run run_indicators() on them eats up too much RAM.
        """
        if rsi:
            self.rsi = RSI(self.data)
            self.rsi.process()
        if stochrsi:
            self.stochrsi = StochasticRSI(self.data)
            self.stochrsi.process()
        if ichimoku:
            self.ichimoku = Ichimoku(self.data)
            self.ichimoku.process()

class Coin:
    """
    Actual entry search tactics defined here.
    Can compare across Timeframes.
    """

    def __init__(self, pair):
        self.pair = pair
        self.dm = DataManager()
        self.tf = {
            "1h": Timeframe(self.pair, "1h"),
            "2h": Timeframe(self.pair, "2h"),
            "4h": Timeframe(self.pair, "4h"),
            "1d": Timeframe(self.pair, "1d")
        }

    def debug(self):
        self.tf["1h"].run_indicators(rsi=True, stochrsi=True)

    def run_indicators(self, rsi=False, stochrsi=False, ichimoku=False):
        for timeframe in self.tf:
            self.tf[timeframe].run_indicators(rsi, stochrsi, ichimoku)

    def rsi_increasing_multiple_timeframes(self):
        timeframes = [self.tf["1h"].rsi.is_increasing(), self.tf["2h"].rsi.is_increasing(), self.tf[
            "4h"].rsi.is_increasing(), self.tf["1d"].rsi.is_increasing()]
        return all(timeframes[:3]), timeframes

    def rsi_is_oversold(self):
        return self.tf["1d"].rsi.is_oversold(period=1)

    def stochrsi_is_oversold(self):
        return self.tf["1d"].stochrsi.is_oversold()


import acm

enbleRealTimePrices = 'enableRealTimePrices'

def TriggerLatch(invokationInfo, toggleName):
    cellInfo = invokationInfo.Parameter('ClickedButton')
    tag = cellInfo.Tag()
    context = cellInfo.Column().Context()
    toggleEval = acm.GetCalculatedValueFromString(None, context, toggleName, tag)
    if (toggleEval.Value() == False):
        toggleEval.Simulate(True, False)
        toggleEval.Simulate(False, False)

def TriggerPriceLatch(invokationInfo):
    TriggerLatch(invokationInfo, enbleRealTimePrices)

def ShowButton(invokationInfo):
    cell = invokationInfo.Parameter("Cell")
    if cell:
        rowObject = cell.RowObject()
        return (rowObject and rowObject.IsKindOf('FPortfolioInstrumentAndTrades'))
    return False