Ejemplo n.º 1
0
def realizado(cat_id):
    freq = { 
            '0':0,
            '1':1,
            '2':7,
            '3':10,
            '4':15,
            '5':28,
            '6':30,
            '7':60,
            '8':90,
            '9':120,
            '10':180,
            '11': 365 
           }  
    cat = Task.query.get(cat_id)
    #Novo registro
        
    cat.status = 3
    cat.update_user = session['usuario']
    cat.update()

    if cat.frequencia != '0':
       print(cat.frequencia)
       data = cat.data + timedelta(days=freq[cat.frequencia])
       novo = Task(cat.titulo,cat.descricao,cat.create_user, cat.frequencia,data, cat.cliente_id)
       novo.add(novo)

    return redirect(url_for('task.mytask'))
Ejemplo n.º 2
0
    def update(self, instance, validated_data):
        raise_errors_on_nested_writes('update', self, validated_data)
        request = self.context['request']
        u = User.objects.get(id=request.user.id)
        if u.employee.position.degree == 9:
            status_code = validated_data.pop('status')
            task = Task(**validated_data)
            task.save()

            employee_id = Employee.objects.get(id=request.user.id)

            status = Status.objects.get(code=status_code)
            t = Task_status.objects.create(status=status, task=task)
            t.editer = employee_id

            if status.code == 4:
                instance.done_date = datetime.today().date()
                print(datetime.today().date())
                t.save()
                instance.save()

        for attr, value in validated_data.items():
            setattr(instance, attr, value)

        return instance
Ejemplo n.º 3
0
def home():
    """
    shows all tasks and lets you make new ones
    """
    form = ToDoForm()
    tasks_5 = Task.query.filter_by(priority=5).all()
    tasks_4 = Task.query.filter_by(priority=4).all()
    tasks_3 = Task.query.filter_by(priority=3).all()
    tasks_2 = Task.query.filter_by(priority=2).all()
    tasks_1 = Task.query.filter_by(priority=1).all()
    print(tasks_1, tasks_2, tasks_3, tasks_4, tasks_5)
    if request.method == 'POST':
        title = form.title.data
        description = form.description.data
        priority = form.priority.data

        if title and priority:
            Task.add(title, description, priority)

            flash(f'Task "{title}" successfully added!', 'alert-green')

        else:
            print('no validation')
            flash(f'Please input a title and choose a priority', 'alert-red')

        return redirect('/')

    else:
        return render_template('home.html',
                               form=form,
                               t5=tasks_5,
                               t4=tasks_4,
                               t3=tasks_3,
                               t2=tasks_2,
                               t1=tasks_1)
Ejemplo n.º 4
0
    def create(self, validated_data):
        sta = validated_data.pop('status')
        taskk = Task(**validated_data)
        taskk.save()
        statuss = Status.objects.get(code=sta)
        t = Task_status.objects.create(status=statuss, task=taskk)

        return taskk
Ejemplo n.º 5
0
def new():
    form = CatForm()
    # tipos de ID
    # 0 - todos
    # C - categoria
    # E - cliente/empresa   
    opcoes = [('0:0','TODOS')]
    categoria = []
    clientes  = []

    for h in Cliente.query.filter(Cliente.status == 0).order_by('nome').all():
       # adicionando clientes na lista
       clientes.append((str(h.id)+':E',h.nome))
       if not  (str(h.categoria.id)+':C',h.categoria.titulo) in categoria:  
          categoria.append((str(h.categoria.id)+':C',h.categoria.titulo))

    opcoes.extend(categoria)
    opcoes.extend(clientes)    

    form.cliente_id.choices = opcoes
    if form.validate_on_submit():       
       titulo      = form.titulo.data
       descricao   = form.descricao.data
       create_user = session['usuario']
       frequencia  = form.frequencia.data
       data        = form.data.data
       cliente_id  = form.cliente_id.data

       (id,cont) = cliente_id.split(":")

       # Verificar se a tarefa eh para todos os clientes
       if cont == '0':          
          for cliente in Cliente.query.filter(Cliente.status == 0):                                 
              tarefa = Task(titulo,descricao,create_user,frequencia,data,cliente.id) 
              tarefa.add(tarefa)

       # Verificar se a tarefa eh por categoria
       if cont == 'C':          
           for cliente in Categoria.query.get(int(id)).cliente.all():
               tarefa = Task(titulo,descricao,create_user,frequencia,data,cliente.id) 
               tarefa.add(tarefa)

       # Verificar se a tarega eh para uma unica empresa        
       if cont == 'E':          
             tarefa = Task(titulo,descricao,create_user,frequencia,data,int(id)) 
             tarefa.add(tarefa)

       return redirect(url_for('task.mytask'))
    return render_template('task/new.html',title='Cadastro de Tarefas',form=form)
Ejemplo n.º 6
0
    def task_vencida(self):
         freq = { 
            '0':0,
            '1':1,
            '2':7,
            '3':10,
            '4':15,
            '5':28,
            '6':30,
            '7':60,
            '8':90,
            '9':120,
            '10':180,
            '11': 365 
           }  

         
         for task in self.tasks:
              if task.data <  hoje:
                 if task.frequencia != '0':
                      data = task.data + timedelta(days=freq[task.frequencia])
                      novo = Task(task.titulo,task.descricao,task.create_user, task.frequencia,data, task.cliente_id)
                      novo.add(novo)                 
Ejemplo n.º 7
0
def new():
    form = FormTask(0)
    if form.validate_on_submit():
        db.session.add(
            Task(
                task_name=form.task_name.data,
                description=form.description.data,
                deadline=form.deadline.data,
                problems=form.problems.data,
                groups=form.groups.data,
            ))
        flash('Adding task is successful!', 'success')
        return redirect(url_for('task.tasklist'))
    return render_template('task_edit.html', form=form)
Ejemplo n.º 8
0
def get_soaringspot_contests(url, client_id, secret):
    import math
    document = get_soaringspot_document(url, client_id, secret)
    print(document)
    contests = list()
    for item in document.items():
        if item[0] == "contests":
            for contest_row in item[1]:
                parameters = {
                    'category':
                    contest_row['category'],
                    'country':
                    contest_row['country'],
                    'end_date':
                    datetime.strptime(contest_row['end_date'], "%Y-%m-%d"),
                    'featured':
                    contest_row['featured'],
                    'name':
                    contest_row['name'],
                    'start_date':
                    datetime.strptime(contest_row['start_date'], "%Y-%m-%d"),
                    'time_zone':
                    contest_row['time_zone']
                }
                contest = Contest(**parameters)

                location_row = contest_row['location']
                parameters = {
                    'altitude': location_row['altitude'],
                    'country': location_row['country'],
                    'latitude': math.degrees(location_row['latitude']),
                    'longitude': math.degrees(location_row['longitude']),
                    'name': location_row['name'],
                    'time_zone': location_row['time_zone']
                }
                location = Location(**parameters)
                contest.location = location

                for contest_class_row in contest_row['classes']:
                    parameters = {
                        'category': contest_class_row['category'],
                        'type': contest_class_row['type']
                    }
                    contest_class = ContestClass(**parameters)
                    contest_class.contest = contest

                    contestants_doc = get_soaringspot_document(
                        contest_class_row.links['contestants'].url, client_id,
                        secret)
                    print(contestants_doc)
                    if 'code' in contestants_doc and contestants_doc[
                            'code'] == 404:
                        print("No contestant")
                    else:
                        for contestant_row in contestants_doc['contestants']:
                            parameters = {
                                'aircraft_model':
                                contestant_row['aircraft_model'],
                                'aircraft_registration':
                                contestant_row['aircraft_registration'],
                                'club':
                                contestant_row['club']
                                if 'club' in contestant_row else None,
                                'contestant_number':
                                contestant_row['contestant_number'],
                                'handicap':
                                contestant_row['handicap'],
                                'live_track_id':
                                contestant_row['live_track_id'],
                                'name':
                                contestant_row['name'],
                                'not_competing':
                                contestant_row['not_competing'],
                                'pure_glider':
                                contestant_row['pure_glider'],
                                'sponsors':
                                contestant_row['sponsors']
                                if 'sponsors' in contestant_row else None
                            }
                            contestant = Contestant(**parameters)
                            contestant.contest_class = contest_class

                            for pilot_row in contestant_row['pilot']:
                                parameters = {
                                    'civl_id': pilot_row['civl_id'],
                                    'email': pilot_row['email'],
                                    'first_name': pilot_row['first_name'],
                                    'igc_id': pilot_row['igc_id'],
                                    'last_name': pilot_row['last_name'],
                                    'nationality': pilot_row['nationality']
                                }
                                pilot = Pilot(**parameters)
                                pilot.contestant = contestant

                    tasks_doc = get_soaringspot_document(
                        contest_class_row.links['tasks'].url, client_id,
                        secret)
                    print(tasks_doc)
                    if 'code' in tasks_doc and tasks_doc['code'] == 404:
                        print("No task")
                    else:
                        for task_row in tasks_doc['tasks']:
                            parameters = {
                                'images':
                                task_row['images'],
                                'no_start':
                                datetime.strptime(task_row['no_start'],
                                                  "%Y-%m-%dT%H:%M:%S"),
                                'result_status':
                                task_row['result_status'],
                                'start_on_entry':
                                task_row['start_on_entry'],
                                'task_date':
                                datetime.strptime(task_row['task_date'],
                                                  "%Y-%m-%d"),
                                'task_distance':
                                task_row['task_distance'],
                                'task_distance_max':
                                task_row['task_distance_max'],
                                'task_distance_min':
                                task_row['task_distance_min'],
                                'task_duration':
                                task_row['task_duration'],
                                'task_number':
                                task_row['task_number'],
                                'task_type':
                                task_row['task_type'],
                                'task_value':
                                task_row['task_value']
                            }
                            task = Task(**parameters)
                            task.contest_class = contest_class

                            points_doc = get_soaringspot_document(
                                task_row.links['points'].url, client_id,
                                secret)
                            print(points_doc)
                            if 'code' in points_doc and points_doc[
                                    'code'] == 404:
                                print("No points")
                            else:
                                for point_row in points_doc['points']:
                                    parameters = {
                                        'name':
                                        point_row['name'],
                                        'latitude':
                                        math.degrees(point_row['latitude']),
                                        'longitude':
                                        math.degrees(point_row['longitude']),
                                        'elevation':
                                        point_row['elevation'],
                                        'point_index':
                                        point_row['point_index'],
                                        'type':
                                        point_row['type'],
                                        'multiple_start':
                                        point_row['multiple_start'],
                                        'distance':
                                        point_row['distance'],
                                        'course_in':
                                        point_row['course_in'],
                                        'course_out':
                                        point_row['course_out'],
                                        'oz_type':
                                        point_row['oz_type'],
                                        'oz_radius1':
                                        point_row['oz_radius1'],
                                        'oz_radius2':
                                        point_row['oz_radius2'],
                                        'oz_angle1':
                                        math.degrees(point_row['oz_angle1']),
                                        'oz_angle12':
                                        math.degrees(point_row['oz_angle12']),
                                        'oz_angle2':
                                        math.degrees(point_row['oz_angle2']),
                                        'oz_line':
                                        point_row['oz_line'],
                                        'oz_max_altitude':
                                        point_row['oz_max_altitude'],
                                        'oz_move':
                                        point_row['oz_move'],
                                        'oz_reduce':
                                        point_row['oz_reduce'],
                                        'speed_section_type':
                                        point_row['speed_section_type']
                                    }
                                    turnpoint = Turnpoint(**parameters)
                                    turnpoint.task = task

                contests.append(contest)

    return contests
Ejemplo n.º 9
0
def get_strepla_class_tasks(competition_id, contest_class_name):
    # This function reads the tasks from a specific contest and class
    # TODO: Include example URL
    # TODO: Generate useful error message, if arguments are not provided
    all_task_url = "https://www.strepla.de/scs/ws/results.ashx?cmd=overviewDays&cID=" + str(
        competition_id) + "&cc=" + str(contest_class_name)
    r = requests.get(all_task_url)
    all_task_data = json.loads(r.text.encode('utf-8'))
    tasks = list()
    for all_task_data_item in all_task_data:
        # print(task_data_item)
        print(all_task_data_item['idCD'], all_task_data_item['date'],
              all_task_data_item['state'])
        if int(all_task_data_item['state']) == 0:
            print("Task not planned for day " + all_task_data_item['date'] +
                  ". Skipping.")
            continue

        if int(all_task_data_item['state']) == 60:
            print("Task neutralized for day " + all_task_data_item['date'] +
                  ". Skipping.")
            continue

        task_url = "http://www.strepla.de/scs/ws/results.ashx?cmd=task&cID=" + str(
            competition_id) + "&idDay=" + str(
                all_task_data_item['idCD']) + "&activeTaskOnly=true"
        print(task_url)
        r = requests.get(task_url)
        task_data = json.loads(r.text.encode('utf-8'))
        print(task_data)
        for task_data_item in task_data['tasks']:
            # print(task_data_item)
            parameters = {
                'result_status':
                all_task_data_item['state'],
                'task_date':
                datetime.strptime(all_task_data_item['date'],
                                  "%Y-%m-%dT%H:%M:%S"),
                'task_distance':
                task_data_item['distance'].replace(' km', '')
            }

            task = Task(**parameters)

            point_index = 0
            for tps in task_data_item['tps']:
                # print("=== tps ===")
                # print(tps)
                if tps['scoring']['type'] == 'LINE':
                    parameters = {
                        'oz_line': True,
                        'type': 'start',
                        'oz_radius1': tps['scoring']['width'] / 2
                    }

                elif tps['scoring']['type'] == 'AAT SECTOR':
                    parameters = {
                        'type': 'point',
                        'oz_radius1': tps['scoring']['radius'],
                        'oz_radius2': 0,
                        'oz_angle1': tps['scoring']['radial1'],
                        'oz_angle2': tps['scoring']['radial2'],
                        'oz_type': 'symmetric',
                        'oz_line': False,
                        'oz_move': False,
                        'oz_reduce': False
                    }

                elif tps['scoring']['type'] == 'KEYHOLE':
                    parameters = {
                        'type': 'point',
                        'oz_radius1': tps['scoring']['radiusSector'],
                        'oz_radius2': tps['scoring']['radiusCylinder'],
                        'oz_angle1': tps['scoring']['angle'] / 2,
                        'oz_angle2': 180,
                        'oz_type': 'symmetric',
                        'oz_line': False,
                        'oz_move': False,
                        'oz_reduce': False
                    }

                    # print("Keyhole TP recognizes.")

                elif tps['scoring']['type'] == 'CYLINDER':
                    parameters = {
                        'type': 'point',
                        'oz_radius1': tps['scoring']['radius'],
                        'oz_radius2': 0,
                        'oz_angle1': 180,
                        'oz_angle2': 0,
                        'oz_type': 'symmetric',
                        'oz_line': False,
                        'oz_move': False,
                        'oz_reduce': False
                    }

                    # print("Cylinder TP recognizes.")

                tp_parameters = {
                    'name': tps['tp']['name'],
                    'latitude': tps['tp']['lat'],
                    'longitude': tps['tp']['lng'],
                    'point_index': point_index
                }

                point_index += 1
                parameters.update(tp_parameters)
                turnpoint = Turnpoint(**parameters)
                # print("=== Turnpoint ===")
                # print(turnpoint)
                turnpoint.task = task

            # task.contest_class = contest_class
            # print(task)
            tasks.append(task)

    return tasks
Ejemplo n.º 10
0
def make_task(id=123, name="Test Task", state="Test State") -> Task:
    state = State(id=1, name="Test State")
    return Task(id=id, name=name, state=state)
Ejemplo n.º 11
0
def create_simple_contest():
    contest = Contest()
    contest.name = "My Fake Contest"
    contest.category = None
    contest.country = "FR"
    contest.end_date = date(2005, 9, 12)
    contest.featured = None
    contest.start_date = date(2005, 9, 3)
    contest.time_zone = None

    location = Location()
    location.name = "St. Auban"
    location.country = "FR"
    location.latitude = 44.1959
    location.longitude = 5.98849
    location.altitude = None
    contest.location = location

    open_class = ContestClass()
    open_class.category = "glider"
    open_class.type = "Open"
    open_class.contest = contest

    m18_class = ContestClass()
    m18_class.category = "glider"
    m18_class.type = "18-meter"
    m18_class.contest = contest

    contestant_open_1 = Contestant()
    contestant_open_1.aircraft_model = "Eta"
    contestant_open_1.aircraft_registration = "D-KONI"
    contestant_open_1.contestant_number = "KG"
    contestant_open_1.live_track_id = "FLRDD0815"
    contestant_open_1.contest_class = open_class

    pilot_open_1 = Pilot()
    pilot_open_1.first_name = "Konstantin"
    pilot_open_1.last_name = "Gründger"
    pilot_open_1.contestant = contestant_open_1

    contestant_open_2 = Contestant()
    contestant_open_2.aircraft_model = "Nimeta"
    contestant_open_2.aircraft_registration = "D-1900"
    contestant_open_2.contestant_number = "XX"
    contestant_open_2.live_track_id = "FLRDD4711"
    contestant_open_2.contest_class = open_class

    pilot_open_2 = Pilot()
    pilot_open_2.first_name = "Dagobert"
    pilot_open_2.last_name = "Duck"
    pilot_open_2.contestant = contestant_open_2

    contestant_18m_1 = Contestant()
    contestant_18m_1.aircraft_model = "ASG 29"
    contestant_18m_1.aircraft_registration = "D-KUGL"
    contestant_18m_1.contestant_number = "GL"
    contestant_18m_1.live_track_id = "OGN0123"
    contestant_18m_1.contest_class = m18_class

    pilot_18m_1 = Pilot()
    pilot_18m_1.first_name = "Gundel"
    pilot_18m_1.last_name = "Gaukelei"
    pilot_18m_1.contestant = contestant_18m_1

    task_1 = Task()
    task_1.no_start = datetime(2015, 9, 3, 10, 0, 0)
    task_1.task_type = "High speed"
    task_1.task_date = date(2005, 9, 3)
    task_1.contest_class = open_class

    task_2 = Task()
    task_2.no_start = datetime(2015, 9, 4, 10, 0, 0)
    task_2.task_date = date(2005, 9, 4)
    task_2.contest_class = open_class

    task_3 = Task()
    task_3.no_start = datetime(2015, 9, 7, 10, 0, 0)
    task_3.task_date = date(2005, 9, 7)
    task_3.contest_class = open_class

    return contest