Ejemplo n.º 1
0
def edit_observers(day_id, observers):
    day = Day.query.get(day_id)
    day_new = Day(day=day.day,
                  comment=day.comment,
                  observers=observers,
                  observatory_id=day.observatory_id)
    day.is_deleted = 1
    addDay(day_new)
    setObsPerDayId(day.id, day_new.id)

    db.session().commit()

    return jsonify({"id": day_new.id})
def test_sameObservatoryDifferentDay(app):
    dayToAdd = Day(day=testDate2,
                   comment='testi',
                   observers='Tom',
                   observatory_id=1)
    dayProperties = {
        'date': testDate,
        'comment': 'testataan',
        'observers': 'Tomppa',
        'observatory_id': 1
    }
    addDay(dayToAdd)
    found = addAndFind(dayProperties)
    assert found == True
def test_ifExistingDayIsAddedCommentAndObserverCanBeModified(app):
    dayProperties = {
        'date': testDate,
        'comment': 'testataan',
        'observers': 'Tomppa',
        'observatory_id': 1
    }
    dayToAdd = Day(day=testDate,
                   comment='testi',
                   observers='Tom',
                   observatory_id=1)
    addDay(dayToAdd)
    found = addAndFind(dayProperties)
    assert found == True
def addAndFind(fields):
    dayToAdd = Day(day=fields['date'],
                   comment=fields['comment'],
                   observers=fields['observers'],
                   observatory_id=fields['observatory_id'])
    addDay(dayToAdd)
    days = getDays()
    found = False
    for day in days:
        if day.day == fields['date'] and day.comment == fields[
                'comment'] and day.observers == fields[
                    'observers'] and day.observatory_id == fields[
                        'observatory_id']:
            found = True
    return found
Ejemplo n.º 5
0
def add_day():

    req = request.get_json()
    observatory_id = getObservatoryId(req['observatory'])

    day = datetime.strptime(req['day'], '%d.%m.%Y')

    day = Day(day=day,
              comment=req['comment'],
              observers=req['observers'],
              observatory_id=observatory_id)

    addDay(day)
    addedId = getDayId(day.day, day.observatory_id)
    return jsonify({'id': addedId})
Ejemplo n.º 6
0
def add_everything():

    req = request.get_json()
    observatory_id = getObservatoryId(req['observatory'])

    day = datetime.strptime(req['day'], '%d.%m.%Y')

    day = Day(day=day,
              comment=req['comment'],
              observers=req['observers'],
              observatory_id=observatory_id)

    addDay(day)
    dayId = getDayId(day.day, day.observatory_id)

    day = getDay(dayId)
    obsId = day.observatory_id

    for obsperiod in req['obsperiods']:
        locId = getLocationId(req['location'], obsId)

        obsp = Observationperiod(
            start_time=datetime.strptime(obsperiod['startTime'], '%H:%M'),
            end_time=datetime.strptime(obsperiod['endTime'], '%H:%M'),
            type_id=getTypeIdByName(req['type']),
            location_id=locId,
            day_id=dayId)
        db.session().add(obsp)

        obspId = getObsPerId(obsp.start_time, obsp.end_time, obsp.location_id,
                             obsp.day_id)

        for observation in obsperiod['observations']:
            shorthand = Shorthand(shorthandrow=observation['shorthandrow'],
                                  observationperiod_id=obspId)
            db.session().add(shorthand)

            shorthand_id = Shorthand.query.filter_by(
                shorthandrow=observation['shorthandrow'],
                observationperiod_id=obspId).first().id

            birdCount = observation['adultUnknownCount'] + observation[
                'adultFemaleCount'] + observation['adultMaleCount'] + observation[
                    'juvenileUnknownCount'] + observation[
                        'juvenileFemaleCount'] + observation[
                            'juvenileMaleCount'] + observation[
                                'subadultUnknownCount'] + observation[
                                    'subadultFemaleCount'] + observation[
                                        'subadultMaleCount'] + observation[
                                            'unknownUnknownCount'] + observation[
                                                'unknownFemaleCount'] + observation[
                                                    'unknownMaleCount']

            observation = Observation(
                species=observation['species'],
                adultUnknownCount=observation['adultUnknownCount'],
                adultFemaleCount=observation['adultFemaleCount'],
                adultMaleCount=observation['adultMaleCount'],
                juvenileUnknownCount=observation['juvenileUnknownCount'],
                juvenileFemaleCount=observation['juvenileFemaleCount'],
                juvenileMaleCount=observation['juvenileMaleCount'],
                subadultUnknownCount=observation['subadultUnknownCount'],
                subadultFemaleCount=observation['subadultFemaleCount'],
                subadultMaleCount=observation['subadultMaleCount'],
                unknownUnknownCount=observation['unknownUnknownCount'],
                unknownFemaleCount=observation['unknownFemaleCount'],
                unknownMaleCount=observation['unknownMaleCount'],
                total_count=birdCount,
                direction=observation['direction'],
                bypassSide=observation['bypassSide'],
                notes=observation['notes'],
                observationperiod_id=obspId,
                shorthand_id=shorthand_id)

            db.session().add(observation)

    db.session().commit()

    return jsonify(req)