Example #1
0
def get_pon_poff(csv, meta_pon, meta_poff):
    csv.pop(0)
    total_power_on = 0
    total_power_off = 0
    for corrida in csv:
        total_power_on = total_power_on + get_power_on(corrida)
        total_power_off = total_power_off + get_power_off(corrida)

    n_corridas = len(csv)
    meta_dia_pon = meta_pon * n_corridas
    meta_dia_poff = meta_poff * n_corridas

    tempo_extra_pon = meta_dia_pon - total_power_on
    tempo_extra_poff = meta_dia_poff - total_power_off

    return [total_power_on, total_power_off, tempo_extra_pon, tempo_extra_poff]
def csvToDict(csv, dic={}):
    if csv:
        # arr = list. arr[0] = occupation. arr[1] = percentage
        arr = csv.pop(0).rstrip('\n').rsplit(',', 1)
        # transform array indexes to key and value in dictionary
        dic[arr[0]] = arr[1]
        return csvToDict(csv, dic)
    return dic
Example #3
0
def __csvToDict(csv, dic={}):
    """Converts csv file into dictionary using recursion"""
    if csv:
        # arr = list. arr[0] = occupation. arr[1] = percentage
        arr = csv.pop(0).rstrip('\n').rsplit(',', 1)
        # transform array indexes to key and value in dictionary
        dic[arr[0]] = arr[1]
        return __csvToDict(csv, dic)
    return dic
Example #4
0
def read_csv_as_dictionary(filename):
    csv = read_csv(filename)
    headers = csv.pop(0)
    data = list()
    for row in csv:
        d = dict()
        for index, header in enumerate(headers):
            d[header] = row[index]
        data.append(d)
    return data
Example #5
0
def read_as_dict_tsv(filename):
    csv = read_tsv(filename)
    headers = csv.pop(0)
    data = list()
    for row in csv:
        d = dict()
        for index, header in enumerate(headers):
            d[header] = row[index]
        data.append(d)
    return data
Example #6
0
from flask_login import login_user, current_user, logout_user, login_required
import sqlite3 as sql
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table, column
import csv as csv
from csv import reader

with sql.connect("app.db") as con:
    con.row_factory = sql.Row
    cur = con.cursor()

    airline_csv = './app/csv/Airlines.csv'
    with open(airline_csv) as file_handler:
        csv = [row for row in reader(file_handler) if any(row)]
        for c in csv:
            cur.execute("INSERT INTO airline (iata, name) VALUES (?,?)",
                        (c[1], c[0]))

    airports_csv = './app/csv/Airports.csv'
    with open(airports_csv) as file_handler:
        csv = [row for row in reader(file_handler) if any(row)]
        headers = csv.pop(0)
        for c in csv:
            cur.execute(
                "INSERT INTO airport (iata, name, city, country, latitude, longitude, time_zone, dst) VALUES (?,?,?,?,?,?,?,?)",
                (c[1], c[2], c[3], c[4], c[5], c[6], c[8], c[9]))

    con.commit()
    cur.close()
Example #7
0
    def iniciar(self, master):
        ######### VARIABLES GENERALES #########
        self.velocidad = 1000 #Milisegundos
        self.vel = -1
        self.contador = -1
        self._job = None
        self.res = None
        self.maxtext = 6
        # CSV
        csv = self.open_csv("data/out1000.csv","\t")
        tags = csv.pop(0)
        lt = len(tags)
        lc = len(csv)
        # print lt,lc
        cumples = []
        for i in xrange(lc):
            c = {}
            for j in xrange(lt):
                c[tags[j]] = csv[i][j]
            cumples.append(c)
        self.cumples = cumples
        #######################################

        self.master = master
        self.master.configure(background='black')
        # self.master.wm_attributes('-transparentcolor','blue')

        if self.fullscreen>0:
            # Full screen
            master.overrideredirect(True)
            master.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
            master.focus_set()  # <-- move focus to this widget
            # Otra opción
            # master.attributes('-fullscreen', True)
        else:
            master.geometry("%dx%d+0+0" % (master.winfo_screenwidth()-16, master.winfo_screenheight()-80))

        master.title(u"Tu cumpleaños en PI")

        master.bind("<Escape>", lambda e: e.widget.quit()) # Python 2
        master.bind("<Key>", self.recibeChar)

        # Background MASCARILLA
        # C = Canvas(master, bg="black", height=root.winfo_screenheight(), width=root.winfo_screenwidth())
        # background_label = Label(master, image=bgfil)
        # background_label.place(x=0, y=0, relwidth=1, relheight=1)
        bgfil = PhotoImage(file = "bg.gif")
        bglabel = Label(master, image=bgfil)
        bglabel.place(x=0, y=0, relwidth=1, relheight=1)
        bglabel.image = bgfil

        # Posicion
        self.posistr = "" # "081284","230301"
        self.posi = StringVar()
        self.posi.set(self.posistr)
        self.labelpo = Label(master, textvariable=self.posi, bg="#000", fg="#eee", width=8, justify="left", font=("Roboto", 64))

        # DESPLIEGUE PI
        self.picustr = "3.1415"
        self.picu = StringVar()
        self.picu.set(self.picustr)
        self.labelp = Label(master, textvariable=self.picu, bg="#000", fg="#fff", width=self.maxtext+1, justify="center", font=("Anonymous Pro", 308))

        # FECHA INGRESADA
        self.fechastr = "" # "081284","230301"
        self.fecha = StringVar()
        self.fecha.set(self.fechastr)
        self.labelf = Label(master, textvariable=self.fecha, bg="black", fg="#eee", width=6, justify="center", font=("Roboto", 96))

        # Resultados extras
        self.resultastr = u"Ingresa tu fecha de cumpleaños: día, mes y año"
        self.resulta = StringVar()
        self.resulta.set(self.resultastr)
        self.labelr = Label(master, textvariable=self.resulta, bg="black", fg="#ccc", width=127, justify="left", font=("Roboto", 16))

        # Posiciona
        self.labelp.place(relx=0, rely=.22)
        self.labelpo.place(relx=0, rely=.07)
        self.labelf.place(relx=0.38, rely=.7)
        self.labelr.place(relx=0, rely=0)

        #######################################
        self.pi = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989'
Example #8
0
        'COM11', 9600,
        timeout=.1)  # debe coincidir con los baudios y el puerto arduino


def open_csv(filename, csv_delimiter):
    data = []
    with open(filename, 'rb') as csvfile:
        csvreader = csv.reader(csvfile, delimiter=csv_delimiter, quotechar="'")
        for row in csvreader:
            data.append(row)
    return data


csv = open_csv("data/out1000.csv", "\t")
tags = csv[0]
csv.pop(0)
lt = len(tags)
lc = len(csv)
# print lc

cumples = []
for i in xrange(lc):
    c = {}
    for j in xrange(lt):
        c[tags[j]] = csv[i][j]
    cumples.append(c)


def buscar(fecha):
    global cumples
    for i in xrange(len(cumples)):
Example #9
0
            self.set_phone(data, name)
        elif(name == 'professions'):
            self.set_profession(data)
        elif(name == 'cities'):
            self.set_city(data, name)

    def to_json(self):
        return json.dumps(self, default=lambda o: o.__dict__,
                          sort_keys=True, indent=4)


# main function
with open(tsv_path, newline='') as tsv_file:
    reader = tsv.reader(tsv_file, delimiter='\t', quotechar='|')
    tsv = list(reader)
    header = tsv.pop(0)
    data = []
    for row in tsv:
        user = User()
        response = {}
        if len(row) == len(header):
            for i, cell in enumerate(row):
                if(header[i][:-1] in plural.keys()):
                    user.set_plurals(cell, plural[header[i][:-1]])
                elif(header[i] in plural.keys()):
                    user.set_plurals(cell, plural[header[i]])
                else:
                    response[header[i]] = cell
            response.update(eval(user.to_json()))
        data.append(response)
    with open('response.json', 'w') as file:
Example #10
0
 def remove_first_row_if_email_is_not_valid(csv):
     if not is_valid_email(csv[0][2]):
         csv.pop(0)