Ejemplo n.º 1
0
def add_usm():
    '''add post by GET request from arduino'''
    mechanism_id = request.args.get('mechanism_id')
    password = request.args.get('password')
    value = request.args.get('value')
    value2 = request.args.get('value2')
    value3 = request.args.get('value3')
    count = request.args.get('count')
    latitude = request.args.get('latitude')
    longitude = request.args.get('longitude')
    try:
        number = dict_mechanisms_number_by_id['usm'][int(mechanism_id)]
    except KeyError:
        return 'Not this id or not usm'
    try:
        mech = Mechanism.query.get(mechanism_id)
    except Exception as e:
        logger.debug(e)
    # if mechanism_id == '33287' and value3 == '0': # FIX
    #     value3 = '15'
    items = mechanism_id, password, latitude, longitude
    test_items = any([item is None for item in items])
    if int(value3) < 5:  # if roller not circle
        value = 0
    if test_items:
        return 'Bad request'
    if password not in post_pass:
        return 'Bad password'
    if int(mechanism_id) not in all_mechanisms_id('usm'):
        return 'Not this id'
    if number in usm_no_move:
        latitude = 0
        longitude = 0
    if latitude == '':
        latitude = 0
        longitude = 0
    if float(latitude) == 0 or float(longitude) == 0:
        try:
            data_mech = db.session.query(Post).filter(
                Post.mechanism_id == mechanism_id).order_by(
                    Post.timestamp.desc()).first()
        except Exception as e:
            logger.debug(e)
        latitude = data_mech.latitude
        longitude = data_mech.longitude
    terminal = which_terminal('usm', number, latitude,
                              longitude)  # exist 9, 11, 13, 15
    new_post = Post(value=value,
                    value2=value2,
                    value3=value3,
                    count=count,
                    latitude=latitude,
                    longitude=longitude,
                    mechanism_id=mechanism_id,
                    terminal=terminal)
    add_fix_post(new_post)
    return f'Success, {str(items)}, {str(datetime.now().strftime("%d.%m.%Y %H:%M:%S"))}'
Ejemplo n.º 2
0
def add_kran():
    '''add post by GET request from arduino'''
    mechanism_id = request.args.get('mechanism_id')
    password = request.args.get('password')
    value = request.args.get('value')
    value3 = request.args.get('value3')
    latitude = request.args.get('latitude')
    longitude = request.args.get('longitude')
    try:
        mech = Mechanism.query.get(mechanism_id)
    except Exception as e:
        logger.debug(e)

    # if mechanism_id == '15510' and value == '1':
    #     value = '2'

    items = mechanism_id, password, latitude, longitude, value, value3
    test_items = any([item is None for item in items])  # if this id is exist
    if test_items:
        return 'Bad request'
    if password not in post_pass:
        return 'Bad password'
    if int(mechanism_id) not in all_mechanisms_id('kran'):
        return 'Not this id or not kran'
    if latitude == '':
        latitude = 0
        longitude = 0
    if float(latitude) == 0 or float(longitude) == 0:
        try:
            data_mech = db.session.query(Post).filter(
                Post.mechanism_id == mechanism_id).order_by(
                    Post.timestamp.desc()).first()
        except Exception as e:
            logger.debug(e)
        latitude = data_mech.latitude
        longitude = data_mech.longitude
    if mech.number in krans_if_3_then_2 and value == '3':
        value = 2
    if mech.number in krans_if_1_then_0 and value == '1':
        value = 4
    k1, b1 = line_kran(mech.number)
    k2, b2 = perpendicular_line_equation(k1, float(latitude), float(longitude))
    latitude, longitude = intersection_point_of_lines(k1, b1, k2, b2)
    terminal = which_terminal('kran', number, latitude,
                              longitude)  # exist 9, 11, 13, 15
    new_post = Post(value=value,
                    value3=value3,
                    latitude=latitude,
                    longitude=longitude,
                    mechanism_id=mechanism_id,
                    terminal=terminal)
    db.session.add(new_post)
    db.session.commit()
    return f'Success, {str(mech.number)},  {str(items)}, {str(datetime.now().strftime("%d.%m.%Y %H:%M:%S"))}'
Ejemplo n.º 3
0
def add_sennebogen():
    '''add post by GET request from arduino'''
    type_mechanism = 'sennebogen'
    number = request.args.get('number')
    password = request.args.get('password')
    x = request.args.get('x')
    y = request.args.get('y')
    count = request.args.get('count')
    latitude = request.args.get('lat')
    longitude = request.args.get('lon')
    mechanism_id = id_by_number(type_mechanism, number)
    try:
        mech = Mechanism.query.get(mechanism_id)
    except Exception as e:
        logger.debug(e)
    items = mechanism_id, password, latitude, longitude, x, y
    test_items = any([item is None for item in items])

    if test_items:
        return 'Bad request'
    if password not in post_pass:
        return 'Bad password'
    if int(mechanism_id) not in all_mechanisms_id(type_mechanism):
        return 'Not this id'
    if latitude == '':
        latitude = 0
        longitude = 0
    if float(latitude) == 0 or float(longitude) == 0:  # get last find value
        try:
            data_mech = db.session.query(Post).filter(
                Post.mechanism_id == mechanism_id).order_by(
                    Post.timestamp.desc()).first()
        except Exception as e:
            logger.debug(e)
        latitude = data_mech.latitude
        longitude = data_mech.longitude
    terminal = which_terminal('sennebogen', number, latitude,
                              longitude)  # exist 9, 11, 13, 15
    new_post = Post(value=x,
                    value2=y,
                    count=count,
                    latitude=latitude,
                    longitude=longitude,
                    mechanism_id=mechanism_id,
                    terminal=terminal)
    add_fix_post(new_post)
    return f'Success, {str(items)}, {str(datetime.now().strftime("%d.%m.%Y %H:%M:%S"))}'
Ejemplo n.º 4
0
def add_kran2():
    '''add post by GET request from arduino'''
    number = int(request.args.get('number'))
    password = request.args.get('passw')
    value = int(request.args.get('value'))
    count = request.args.get('count')
    latitude = request.args.get('lat')
    longitude = request.args.get('lon')
    x = abs(int(request.args.get('x')))  # accelerometr x-axis
    y = abs(int(request.args.get('y')))  # accelerometr y-axis
    try:
        mechanism_id = dict_mechanisms_id_by_number['kran'][number]
    except KeyError:
        return 'Not this id or not kran'
    try:
        mech = Mechanism.query.get(mechanism_id)
    except Exception as e:
        logger.debug(e)
    # if mechanism_id == 4513 and value == 1: # FIX
    #     value = 2
    items = mechanism_id, password, latitude, longitude, value, count
    test_items = any([item is None for item in items])  # if this id is exist
    if test_items:
        return 'Bad request'
    if password not in post_pass:
        return 'Bad password'
    if number in krans_if_3_then_2 and value == 3:
        value = 2
    if number in krans_if_1_then_0 and value == 1:
        value = 4  # 4 work how 0
    if value == 0 and ((x > 500 and y > 500) or x > 850 or y > 850):
        value = 5  # kran move
    if latitude == '':
        latitude = 0
        longitude = 0
    latitude, longitude = corect_position(mech, latitude, longitude)
    terminal = which_terminal('kran', number, latitude,
                              longitude)  # exist 9, 11, 13, 15
    new_post = Post(value=value,
                    count=count,
                    latitude=latitude,
                    longitude=longitude,
                    mechanism_id=mechanism_id,
                    terminal=terminal)
    db.session.add(new_post)
    db.session.commit()
    return f'Success, {str(mech.number)},  {str(items)}, {str(datetime.now().strftime("%d.%m.%Y %H:%M:%S"))}'
Ejemplo n.º 5
0
 line = line.split('&')
 time = re.search(r'\[.*\]', line[0])[0]
 time = time[1:21]
 time = datetime.strptime(time, '%d/%b/%Y:%H:%M:%S')
 if time < time_start or time > time_finish:
     continue
 mechanism_id = line[0].split('=')[1]
 number = dict_mechanisms_number_by_id['usm'][int(mechanism_id)]
 passw = line[1].split('=')[1]
 value = line[2].split('=')[1]
 value2 = line[3].split('=')[1]
 value3 = line[4].split('=')[1]
 count = line[5].split('=')[1]
 lat = line[6].split('=')[1]
 lon = line[7].split(' ')[0].split('=')[1]
 terminal = which_terminal('usm', number, lat, lon)
 timestamp = time - timedelta(hours=10)
 new_post = Post(
     timestamp=timestamp,
     mechanism_id=mechanism_id,
     value=value,
     value2=value2,
     value3=value3,
     count=count,
     latitude=lat,
     longitude=lon,
     terminal=terminal,
 )
 if mechanism_id != '34214':
     continue
 print(timestamp, number, mechanism_id, value, value2, value3, count,
Ejemplo n.º 6
0
 def test_terminal(self):
     for question, coord in self.data_test_terminal:  #attention first lon
         ans = which_terminal(coord[1], coord[0])
         self.assertEqual(question, ans)