Esempio n. 1
0
    def test_legislature_early_closing(self):
        '''
        Test the mass update of mandates if deadline date of legislature
        is changed
        '''
        mandate = self.browse_ref(
            '%s.stam_pauline_bourgmestre' % self._module_ns)
        legislature = mandate.legislature_id
        start = mandate.start_date
        dstart = fields.Date.from_string(start)
        today = fields.Date.today()
        dtoday = fields.Date.from_string(today)

        dpast = dtoday - TD(days=1)
        with self.assertRaises(orm.except_orm):
            legislature.write({'deadline_date': fields.Date.to_string(dpast)})
        if dtoday < dstart:
            dfuture = dstart + TD(days=3)
            future = fields.Date.to_string(dfuture)
            legislature.write({'deadline_date': future})
            self.assertEqual(legislature.deadline_date, future)
            self.assertEqual(mandate.deadline_date, future)
            dpast = dstart - TD(days=1)
            with testtool.disable_log_error(self.env.cr):
                with self.assertRaises(psycopg2.IntegrityError):
                    legislature.write(
                        {'deadline_date': fields.Date.to_string(dpast)})
Esempio n. 2
0
    def test_media_tempo_espera_qtd_minima_turnos(self):

        posto1 = h.get_or_create_posto(['l1', 'f1', 'p1'])
        cliente1 = h.get_or_create_cliente('c1')

        # (inicio atendimento, tempo atendimento): Simulamos 2 postos de atendimento
        esperas = [(0, 355), (15, 299), (356, 344), (314, 600), (700, 245),
                   (914, 33)]
        media = sum(map(lambda x: x[1], esperas)) / len(esperas)
        inicio_atendimento = TZ.now()
        fim_atendimento = inicio_atendimento + TD(seconds=950)

        for espera in esperas:
            t1 = cliente1.entrar_na_fila(posto1.fila.id, test_mode=True)
            t1.estado = Turno.ATENDIDO
            t1.inicio_espera_date = inicio_atendimento + TD(seconds=espera[0])
            t1.fim_espera_date = t1.inicio_espera_date + TD(seconds=espera[1])
            t1.save()

        t1.fila.refresh_from_db()

        t1.fila.media_espera = 500
        t1.fila.save()

        t1.fila.refresh_from_db()

        with self.assertRaises(SemQtdMinTurnosParaCalcularMediaEspera):
            t1.fila.calcular_media_espera(dt_from=inicio_atendimento,
                                          dt_to=fim_atendimento,
                                          qtd_min_turnos=7)

        t1.refresh_from_db()

        self.assertEqual(t1.fila.media_espera, 500)
Esempio n. 3
0
def write_compiled(obs, furby):
    ofile = conf.final_result_file
    if os.path.exists(ofile):
        f = open(ofile, 'a')
    else:
        f = open(ofile, 'w')
        header_string = "UTC\tLocalTime\tzapf(wted)\tzapf(bwted)\tFurby\tBeam\t"
        for pipeline in furby.pipelines:
            header_string += "{0}.snr\t{0}.dm\t{0}.width\t{0}.prob\t{0}.tstamp\t".format(
                pipeline)
        f.write(header_string + "\n")

    beam = furby.pipelines[0].beam
    ut = DT.strptime(obs.utc, "%Y-%m-%d-%H:%M:%S")
    timezone_diff = TD(hours=10)
    local_time = ut + timezone_diff
    ctime = local_time.strftime("%y-%m-%d_%H:%M:%S")
    #zapf_wt, zapf_bwt = get_zapfs(obs.utc)
    zapf_wt, zapf_bwt = 0, 0
    data_string = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t".format(
        obs.utc, ctime, str(zapf_wt), str(zapf_bwt), furby.name, str(beam))
    for p in furby.pipelines:
        data_string += "{0}\t{1}\t{2}\t{3}\t{4}\t".format(
            str(p.snr), str(p.dm), str(p.width), str(p.prob), str(p.tstamp))

    f.write(data_string + "\n")
    f.close()
Esempio n. 4
0
    def handle(self, *args, **options):

        now = TZ.now()
        de = now - TD(seconds=options['from'])
        ate = now - TD(seconds=options['to'])
        qtd_min_turnos = options['quan_min_turnos']

        print(qtd_min_turnos)
        for fila in Fila.objects.all():
            try:
                fila.calcular_media_espera(de, ate, qtd_min_turnos)
                self.stdout.write(
                    self.style.SUCCESS(
                        'Media de tempo de atendimento para fila %s: %s segundos'
                        % (fila.nome, int(fila.media_espera))))
            except (SemQtdMinTurnosParaCalcularMediaEspera,
                    SemTurnosParaCalcularMediaEspera) as e:
                self.stdout.write(self.style.WARNING('ADV: %s' % e))
def add_gigasecond(birth):
    '''Returns when a person has lived for
    10**9 seconds

    Arguments:
        birth = datetime(year, month, day)
    Returns: 
        Moment person has live for 10**9 seconds
    '''
    time_delta = TD(seconds=10**9)
    birth = birth

    return (time_delta + birth)
Esempio n. 6
0
    def timer(self):

        warm_up, med_length = self.session_input()

        td_length_remaining = TD(minutes=int(med_length))
        print('')
        start = input("Push any key to start. Push Ctrl-C to exit.")
        entry = self.entry()
        entry["conn"], entry["cur"] = self.conn, self.cur

        try:
            if warm_up != 0:  #checks if warm_up is non-zero number
                print("Warm up start!")
                while warm_up != 0:  #keeps looping until warm_up is 0

                    warm_string = str(
                        TD(seconds=int(warm_up)))  #converts to human readable
                    print(warm_string, end='\r')
                    warm_up -= 1  #deincriments by 1

                    sleep(
                        1
                    )  #sleeps so it doesn't run through micro seconds printing same thing.
                entry['warmUp'] = warm_string
        except KeyboardInterrupt:
            exit("Goodbye!")

        print("")
        print("Meditation time....")
        print("Push Ctrl-C to end at any time.")
        print("")

        try:
            sfx = self.bells("tinsha.wav", 12000)
            while td_length_remaining != TD(hours=0, minutes=0, seconds=0):
                print(str(td_length_remaining), end='\r')
                td_length_remaining -= TD(seconds=1)

                sleep(1)

        except KeyboardInterrupt:
            print('')
            short_time = str(TD(minutes=int(med_length)) - td_length_remaining)
            print("You sat {} minutes".format(short_time))
            entry["sLength"] = short_time
            exit('Goodbye!')

        entry["sLength"] = str(TD(minutes=int(med_length)))
        self.bells("tinsha.wav", 4800)
        print("Yay! You made it!")

        super().add_session(**entry)
        sleep(5)
        self.session_records()
Esempio n. 7
0
    def test_media_tempo_espera_um_turno(self):

        posto1 = h.get_or_create_posto(['l1', 'f1', 'p1'])
        cliente1 = h.get_or_create_cliente('c1')
        t1 = cliente1.entrar_na_fila(posto1.fila.id, test_mode=True)

        t1.estado = Turno.ATENDIDO
        t1.inicio_espera_date = TZ.now()
        t1.fim_espera_date = t1.inicio_espera_date + TD(seconds=355)

        t1.save()

        t1.fila.refresh_from_db()

        t1.fila.calcular_media_espera(dt_from=t1.inicio_espera_date,
                                      dt_to=t1.fim_espera_date)

        self.assertEqual(t1.fila.media_espera, 355)
Esempio n. 8
0
from datetime import timedelta as TD
import math


def discount(h, c):
    if 20 <= h:
        return c * 0.8
    return c


h, m = map(int, input().split(' '))
H, D, C, N = map(int, input().split(' '))

now = discount(h, C) * math.ceil(H / N)
later = now
if h < 20:
    sec_until_8 = TD(hours=20) - TD(hours=h, minutes=m)
    hunger = H + D * math.ceil(sec_until_8.seconds / 60)
    later = discount(20, C) * math.ceil(hunger / N)

print('{:.4f}'.format(min(now, later)))
Esempio n. 9
0
 def delete_test(self, cur, conn):
     cur.execute(
         'DELETE FROM session WHERE sitting_length=? OR sitting_length=?',
         (str(TD(minutes=1)), str(TD(minutes=0))))
     conn.commit()
# Imports

import datetime  # Basic import
delta = datetime.timedelta(days=5)

import datetime as DT  # Renaming the import
delta = DT.timedelta(days=5)

from datetime import timedelta  # Pulling it into our namespace
delta = timedelta(days=5)

from datetime import timedelta as TD  # Pulling it into our namespace and renaming it
delta = TD(days=5)

import tools.cutters.saw  # Importing a module from a nested package
tools.cutters.saw.saw_things()  # Call a function on imported package

from tools.cutters.knife import knife_things as cut  # Import just a function
cut()
Esempio n. 11
0
def tomorrow(dtObj=today()):
    return dtObj + TD(days=1)
Esempio n. 12
0
def yesterday(dtObj=DT.today()):
    return dtObj + TD(days=-1)