コード例 #1
0
def data_create(point_id):
    point = Point.query.get_or_404(point_id)

    if point.type == "지중경사계":
        form = DataVerticalForm()
    elif point.type == "하중계":
        form = DataLoadcellForm()
    else:
        form = DataForm()

    if request.method == 'POST' and form.validate_on_submit():
        if point.type == '지중경사계':
            data = Data(measuringdate=form.measuringdate.data, data09=form.data09.data)
        elif point.type == "하중계":
            data = Data(measuringdate=form.measuringdate.data, data01=form.data01.data,
                        data02=form.data02.data, data03=form.data03.data)
        else:
            data = Data(measuringdate=form.measuringdate.data, data01=form.data01.data)
        point.data_set.append(data)
        db.session.add(data)
        db.session.commit()
        return redirect(url_for('point.point_detail', point_id=point_id))

    if point.type == '지중경사계':
        return render_template('data/vertical_form.html', form=form)
    else:
        return render_template('data/data_form.html', form=form)
コード例 #2
0
ファイル: sensor.py プロジェクト: teznatech/IoT-Bootcamp
    def read_data(self):
        threading.Timer(60.0, self.read_data).start()
        humidity, temperature = Adafruit_DHT.read_retry(
            self.DHT_SENSOR, self.DHT_PIN)
        if humidity is not None and temperature is not None\
         and humidity < 101 and humidity > 0:
            temperature = '{0:.2f}'.format(temperature)
            humidity = '{0:.2f}'.format(humidity)
            with self.app.app_context():
                if Data.query.count() > 10000:
                    Data.query.delete()

                data = Data(temperature=temperature, humidity=humidity)
                db.session.add(data)
                db.session.commit()
                data = []
                date = time.strftime('%Y-%m-%d %H:%M')
                data.append(date)
                data.append(temperature)
                data.append(humidity)
                #write to data file
                with open(self.record_file, "a") as f_data:
                    wr = csv.writer(f_data)
                    wr.writerow(data)
                self.write_html()
コード例 #3
0
def post_data():
    data = request.get_json() or {}
    if 'string' not in data:
        return bad_request("request must include 'string' field")
    Serial().write(data['string'])
    response = jsonify(Data(Serial().in_waiting(), data['string']).to_dict())
    response.status_code = 201
    return response
コード例 #4
0
async def create_entry(payload: DataPayloadSchema) -> DataResponseSchema:
    entry = Data(parameter=payload.parameter,
                 location=payload.location,
                 date=payload.date,
                 mean=payload.mean,
                 upper=payload.upper,
                 lower=payload.lower)
    await entry.save()
    return entry
コード例 #5
0
ファイル: views.py プロジェクト: EricSchles/example_flask_app
def index():
    if request.method=="POST":
        print "got here"
        data = request.form.get("data")
        d = Data(data)
        db.session.add(d)
        db.session.commit()
        return render_template("index.html",entered_data=data)
    return render_template("index.html")
コード例 #6
0
def dataEntry():
    form = DataEntry()
    if form.validate_on_submit():
        sensor = Sensor.query.filter_by(name=form.sensorName.data).first()
        data = Data(temp=form.temperature.data, humidity=form.humidity.data,sensor_id=sensor.id)
        db.session.add(data)
        db.session.commit()
        return redirect(url_for('dataEntry'))
    return render_template('enter-data.html',form=form)
コード例 #7
0
ファイル: views.py プロジェクト: tubleronchik/DataCollector
def success():
    print("Hi")
    if (request.method == 'POST'):
        age_ = request.form['age']
        country_ = request.form['country']
        data = Data(age_, country_)
        db.session.add(data)
        db.session.commit()
    return render_template("success.html")
コード例 #8
0
def save_data(filename: str, form_data: list):
    '''
    get filename and list of categories
    saves data to a file and db
    '''
    dict_data = {'categories': form_data, 'timestamp': time()}
    with open(filename, 'w') as f:
        json.dump(dict_data, f)
    d = Data(data=json.dumps(dict_data))
    db.session.add(d)
コード例 #9
0
ファイル: main.py プロジェクト: harshit496/tagup_challenge
 def post(self):
     new_post = Data(timestamp=request.json['timestamp'],
                     value1=request.json['value1'],
                     value2=request.json['value2'],
                     value3=request.json['value3'],
                     creationDate=time.time(),
                     lastModificationDate=time.time())
     db.session.add(new_post)
     db.session.commit()
     return post_schema.dump(new_post)
コード例 #10
0
def upload_data(current_user):
    if not current_user.admin:
        return jsonify({'message':
                        'Not allowed to perform that function!'}), 401

    file = request.files["file"]
    new_data = Data(public_id=str(uuid.uuid4()), data=file.read())
    db.session.add(new_data)
    db.session.commit()
    return jsonify({'message': 'New data added!'})
コード例 #11
0
def create_data():
    print('开始生成数据')
    import numpy as np

    nSampleNum = 5120 / 2
    ncount = 1024.0
    df = nSampleNum / ncount
    sampleTime = ncount / nSampleNum

    x = np.linspace(0, sampleTime, ncount)

    # 三个标准正弦波形
    sinx = np.sin(2 * np.pi * 250 * x)
    sinx2 = 0.5 * np.sin(2 * np.pi * 500 * x)
    sinx3 = 0.3 * np.sin(2 * np.pi * 1000 * x)

    # 叠加时域
    sinx += sinx2
    sinx += sinx3

    i = 0
    equipments = Equipment.objects.all()
    time = timezone.now()

    while i < len(equipments):
        equipment = equipments[i]
        points = Point.objects.filter(equipment=equipment)
        j = 0
        while j < len(points):
            point = points[j]
            k = 0
            data_list = []
            while k < len(x) * (60 * 60 * 8):
                time += datetime.timedelta(microseconds=976.5625)

                data = Data(equipment=equipment,
                            point=point,
                            amplitude=sinx[k % len(x)],
                            add_time=time)

                data_list.append(data)

                if k % (1024 * 60 * 15) == 0:
                    print('设备: %s, 测点: %s, 已生成: %d ' %
                          (equipment.name, point.number, k))
                    Data.objects.bulk_create(data_list)
                    data_list = []
                    print('设备: %s, 测点: %s , %d 小时数据已存储' %
                          (equipment.name, point.number, k / (1024 * 60 * 60)))
                k += 1

            j += 1
        i += 1

    print('生成数据完成')
コード例 #12
0
def parseJsonData(response, datatype, user_id):

    objs = response.json()
    #objs = json.loads(response.text)
    for index in range(len(objs[datatype + '-intraday']['dataset'])):
        newdata = Data(
            user_id=user_id,
            date=objs[datatype][0]['dateTime'],
            time=objs[datatype + '-intraday']['dataset'][index]['time'],
            data_type=datatype,
            value=objs[datatype + '-intraday']['dataset'][index]['value'])
        newdata.save()
コード例 #13
0
ファイル: load_data.py プロジェクト: rsrp94/Word_search
    def handle(self, *args, **options):
        input = options["input"]
        f_obj = open(input)
        count = 0
        recs = []
        for line in f_obj:
            count += 1
            line = line.strip()
            word, occur = line.split("\t")
            recs.append(Data(word=word, count=occur))
            if count == 500:
                Data.objects.bulk_create(recs)
                recs = []
                count = 0

        f_obj.close()
コード例 #14
0
ファイル: tasks.py プロジェクト: kirimaks/weather_charts
def worldseatemp_temp():
    logging.debug("worldseatemp_temp() started")
    source_name = "worldseatemp"

    source_id = DataSource.query.filter(DataSource.source_name == source_name)
    source_id = source_id.all()

    if not source_id:
        source_id = create_source(source_name)
    else:
        source_id = source_id[0].source_id

    temp = get_temp_worldseatemp()

    data = Data(indicator=temp, chart_id=chart_id, source_id=source_id)

    db_session.add(data)
    db_session.commit()
コード例 #15
0
ファイル: views.py プロジェクト: dogsuned/MyFlask
def UpdateDb(fpath, year, month):
    workbook = xlrd.open_workbook(fpath)

    if workbook == None:
        log_info('无法打开该文件')
        return False

    names = workbook.sheet_names()
    if not SALARY_SHEET_NAME in names:
        log_info('未找到数据表')
        return False

    sheet = workbook.sheet_by_name(SALARY_SHEET_NAME)

    label_pre = sheet.row_values(3)
    label = sheet.row_values(4)
    for i in range(0, len(label)):
        if label[i] == '':
            label[i] = label_pre[i]

    users = sheet.col_values(1)
    if len(users) < 6:
        log_info('无效数据表')
        return False

    dic = {}
    dic['月份'] = month
    for i in range(5, len(users) - 6):
        for j in range(1, sheet.ncols - 2):
            dic[label[j].strip()] = sheet.cell_value(i, j)
        obj = json.dumps(dic)

        username = users[i]
        user = User.query.filter_by(name=username).first()
        if user == None:
            user = NewUser(username)

        data = Data(year, month, obj)
        db.session.add(data)
        user.data.append(data)

    db.session.commit()
    return True
コード例 #16
0
def main():
    first_names = [
        "John", "Charlie", "Bob", "Rick", "Steven", "Eric", "Alex", "Rachel",
        "Sarah", "Margie", "Maggie", "Albert"
    ]
    last_names = [
        "Johnson", "Harding", "Phillips", "Stevens", "Richardson", "Archer",
        "Black", "Brown", "Steele", "Powers"
    ]
    for i in xrange(50):
        first_name = first_names[randint(0, len(first_names) - 1)]
        last_name = last_names[randint(0, len(last_names) - 1)]
        name = first_name + " " + last_name
        email = first_name + last_name + "@gmail.com"
        data = Data(
            datetime(randint(2011, 2015), randint(1, 10), randint(1, 28), 1,
                     1), name, email)
        db.session.add(data)
        db.session.commit()
コード例 #17
0
ファイル: views.py プロジェクト: strawwj/my_code
def data(did, sid):
    print(type(request.json), request.json)
    device = g.current_user.devices.filter_by(id=did).first()
    if device is None:
        return jsonify({'status': 404, 'info': '找不到你的设备'})

    sensor = device.sensors.filter_by(id=sid).first()
    if sensor is None:
        return jsonify({'status': 404, 'info': '找不到你的传感器'})
    print(request.json)
    if request.json is None:
        return jsonify({'status': 404, 'info': '找不到你的数据'})

    if 'data' not in request.json.keys():
        return jsonify({'status': 404, 'info': '找不到你的数据'})

    # 判断报警

    data = Data()
    data.data = request.json.get('data')
    data.sensor_id = sid
    db.session.add(data)
    db.session.commit()
    if data.data > sensor.max:
        alert = Alert()
        alert.sensor_id = sensor.id
        alert.reason = '超出最大值'
        alert.data_id = data.id
        alert.current_max = sensor.max
        alert.current_min = sensor.min
        db.session.add(alert)
        db.session.commit()
    if data.data < sensor.max:
        alert = Alert()
        alert.sensor_id = sensor.id
        alert.reason = '低于最小值'
        alert.data_id = data.id
        alert.current_max = sensor.max
        alert.current_min = sensor.min
        db.session.add(alert)
        db.session.commit()
    return jsonify({'status': 200})
コード例 #18
0
def script():
    """Сбор данных для таблицы через поиск яндекса."""
    keyword = request.args.get('keyword')
    if not keyword:
        return 'I need keyword', 400
    r = requests.get(f'http://yandex.ru/?q={keyword}')
    soup = BeautifulSoup(r.content, 'lxml')
    headers = soup.find('body').find_all('h2')
    links = [
        headers[i].find('a')['href'] for i in range(len(headers))
        if headers[i].find('a')
    ]
    data = []
    for link in links:
        if link.startswith('http://yabs'):
            r = requests.get(link)
            soup = BeautifulSoup(r.content, 'lxml')
            url = soup.find('noscript').find('meta')['content'][7:-1]
            start = time()
            r = requests.get(url)
            finish = time() - start
        else:
            try:
                url = link
                start = time()
                r = requests.get(link)
                finish = time() - start
            except:
                continue
        data.append({
            'keyword': keyword,
            'code_response': r.status_code,
            'size_page': len(r.content),
            'url': url,
            'domain': r.headers.get('domain') or url,
            'timeload': int(finish)
        })
    for elem in data:
        d = Data(**elem)
        db.session.add(d)
        db.session.commit()
    return 'OK', 200
コード例 #19
0
def login():
    form1 = EnterDBInfo(request.form) 
    
    if request.method == 'POST' and form1.validate():
        user_name=form1.username.data
        query_test=Data.query.filter_by(nickname=user_name.encode('ascii','ignore')).first()
        if query_test!=None:
            string_response='You already have an account. Please sign in.'
            return render_template('thanks2.html', output=string_response) 
        else:
            data_entered = Data(nickname=form1.username.data,password=form1.passwd.data,inst=form1.institute.data,emailaddress=form1.email_ad.data)
            try:     
                db.session.add(data_entered)
                db.session.commit()        
                db.session.close()
            except:
                db.session.rollback()
            return render_template('thanks.html', nickname=form1.username.data,password=form1.passwd.data)
        
    return render_template('login.html', form=form1)
コード例 #20
0
def log_data(u_id, d_id):
    if g.current_user.id != u_id or Device.query.get(
            d_id).user_id != g.current_user.id:
        abort(403)

    data = request.get_json() or {}

    if 'value' not in data:
        return bad_request('must include a value')

    logging = Data(device=Device.query.get(d_id))
    logging.date = datetime.utcnow()
    logging.from_dict(data)
    db.session.add(logging)
    db.session.commit()
    response = jsonify(logging.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_device', id=u_id)

    return response
コード例 #21
0
def createDataEntry():
    data = request.get_json() or {}
    print(data)

    if 'device_id' not in data or 'room_temp' not in data or 'room_humd' not in data or 'baby_temp' not in data:
        return bad_request('Corrupted data!')

    #Create data object
    dataEntry = Data()
    dataEntry.from_dict(data)

    print(dataEntry)

    #Update db
    db.session.add(dataEntry)
    db.session.commit()

    #Return the response
    response = jsonify()
    response.status_code = 201
    return response
コード例 #22
0
def submit():
    if request.method == "POST":
        new = Data()
        new.id = uuid.uuid1().hex
        new.url = request.form.get('url')
        new.email = request.form.get('email')
        if not new.email:
            new.email = ""
        if new.url:
            subprocess.Popen([sys.executable, 'app\hashing.py'] +
                             [new.id, new.url, new.email],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             env=os.environ.copy())
        else:
            return (jsonify('Error 400 url not given'))
        new.md5_hash = ""

        new.state = "working"
        db.session.add(new)
        db.session.commit()
    return (new.id)
コード例 #23
0
ファイル: views.py プロジェクト: fengchuan1021/webresovepcap
def storemysql(f, caps):
    file = Capfile(filename=f)
    file.save()
    arr = []
    for ind, cap in enumerate(caps):
        data = Data()
        data.fileid = file
        data.sniff_time = cap.sniff_time
        data.length = cap.length
        data.ind = ind
        if hasattr(cap, 'ip'):
            data.srcip = cap.ip.src
            data.dstip = cap.ip.dst
            data.ttl = cap.ip.ttl
            data.version = int(cap.ip.version)
            ttl = int(data.ttl)
            if ttl <= 32:
                data.hop = 32 - ttl
            elif ttl <= 64:
                data.hop = 64 - ttl
            elif ttl <= 128:
                data.hop = 128 - ttl
            elif ttl <= 255:
                data.hop = 255 - ttl

        if hasattr(cap, 'eth'):
            data.srcmac = cap.eth.src
            data.dstmac = cap.eth.dst
        data.proto_name = getprotocal(cap)
        data.layer_level = getlayer_level(data.proto_name)
        data.content = ''
        arr.append(data)
    if arr:
        Data.objects.bulk_create(arr)

    return file.id
コード例 #24
0
ファイル: routes.py プロジェクト: poymanov/data-collector-app
def success():
    form = DataForm()
    email = form.email.data
    height = form.height.data

    if form.validate_on_submit():
        if Data.query.filter_by(email=email).first():
            flash('Validation errors')
            form.email.errors.append('Email address already exists.')
            return render_template('home.html', form=form)

        data = Data(email=email, height=height)
        db.session.add(data)
        db.session.commit()

        average_height = db.session.query(func.avg(Data.height)).scalar()
        average_height = round(average_height, 1)
        people_count = db.session.query(Data).count()

        text_body = render_template('/email/height_mail.txt',
                                    height=height,
                                    average_height=average_height,
                                    people_count=people_count)
        html_body = render_template('/email/height_mail.html',
                                    height=height,
                                    average_height=average_height,
                                    people_count=people_count)
        send_email(subject="Height data",
                   recipients=[email],
                   text_body=text_body,
                   html_body=html_body)

        return render_template('success.html')
    else:
        flash('Validation errors')
        return render_template('home.html', form=form)
コード例 #25
0
def get_data():
    data = Data(Serial().in_waiting(), Serial().read(10))
    return jsonify(data.to_dict())
コード例 #26
0
ファイル: views.py プロジェクト: caoxu9/flask
def newdata(device_id, sensor_id):
    count = current_app.config['DATA_COUNT']
    interval = current_app.config['DATA_INTERCAL']
    d = g.current_user.devices.filter_by(id=device_id).first()
    if d is None:
        return jsonify({'status': 404})
    else:
        s = d.sensors.filter_by(id=sensor_id).first()
        if s is None:
            return jsonify({'status': 404})
        else:
            if request.method == 'GET':
                newdata = s.datas.order_by(Data.id.desc()).first()
                if newdata is None:
                    return jsonify({'status': 404})
                else:
                    return jsonify({'status': 200, 'data': newdata.to_json()})
            else:
                data_json = request.json
                if data_json is None:
                    return jsonify({'status': 404})
                else:
                    data = data_json.get('data')
                    if data is None:
                        return jsonify({'status': 404})
                    else:
                        old_time = time.mktime(
                            s.datas.order_by(
                                Data.id.desc()).first().time.timetuple())
                        new_time = time.mktime(datetime.utcnow().timetuple())
                        if new_time - old_time < interval:
                            return jsonify({
                                'status': 412,
                                'tip': '请求时间间隔不能低于20s'
                            })
                        else:
                            d = Data()
                            print(s.datas.count())
                            if s.datas.count() + 1 > count:
                                sd = s.datas.first()
                                db.session.delete(sd)
                            d.sensor_id = sensor_id
                            d.data = data
                            db.session.add(d)

                            alert = Waring()
                            alert.max = s.max
                            alert.min = s.min
                            alert.sensor_id = sensor_id
                            alert.device_id = device_id
                            alert.user_id = g.current_user.id
                            alert.data = d.data
                            if s.max > s.min:
                                if d.data > s.max:
                                    alert.about = '超过上限'
                                    db.session.add(alert)
                                if d.data < s.min:
                                    alert.about = '低于下限'
                                    db.session.add(alert)
                            db.session.commit()

                            return jsonify({'status': 200, 'success': True})
コード例 #27
0
ファイル: __init__.py プロジェクト: jbrak/Flask_Practice
def write():
    db.session.rollback()
    d = Data(date=datetime.now(), temp=t())
    db.session.add(d)
    db.session.commit()
コード例 #28
0
ファイル: views.py プロジェクト: afcarl/python_datastructure
def add():
    dicter = json.loads(request.data)
    data = Data(int(dicter["data"]))
    db.session.add(data)
    db.session.commit()
    return "successfully added " + str(dicter["data"])
コード例 #29
0
ファイル: data_service.py プロジェクト: max-block/mb-base1
 def generate_data(self):
     status = random.choice(list(DataStatus))
     value = random.randint(0, 1_000_000)
     self.dlog("data_generated", {"status": status, "value": value, "large-data": "abc" * 100})
     self.send_telegram_message(f"a new data: {value}")
     return self.db.data.insert_one(Data(status=status, value=value))
コード例 #30
0
def ContactData():
    form = ContactDataForm()
    keys = session.keys()
    if ('username' in keys and session['username'] == 'admin'):
        if form.validate_on_submit():
            # return 'inside'
            # return redirect(url_for('test'))
            Contact_Record_Type = form.Contact_Record_Type.data
            Created_Date = form.Created_Date.data
            Contact_ID = form.Contact_ID.data
            Contact_Owner = form.Contact_Owner.data
            First_Name = form.First_Name.data
            Last_Name = form.Last_Name.data
            Title = form.Title.data
            Account_Name = form.Account_Name.data
            Industry = form.Industry.data
            Email1 = form.Email1.data
            Email2 = form.Email2.data
            Phone = form.Phone.data
            Linkedin_URL = form.Linkedin_URL.data
            Contact_Status = form.Contact_Status.data
            New_Lead_Source = form.New_Lead_Source.data
            Services = form.Services.data
            Products = form.Products.data
            Mailing_City = form.Mailing_City.data
            Mailing_State = form.Mailing_State.data
            Mailing_Country = form.Mailing_Country.data
            Region = form.Region.data
            Campaigns_targetted = form.Campaigns_targetted.data
            Email_Valid = form.Email_Valid.data
            Last_Targetted = form.Last_Targetted.data
            data = Data(Contact_Record_Type=Contact_Record_Type,
                        Created_Date=Created_Date,
                        Contact_ID=Contact_ID,
                        Contact_Owner=Contact_Owner,
                        First_Name=First_Name,
                        Last_Name=Last_Name,
                        Title=Title,
                        Account_Name=Account_Name,
                        Industry=Industry,
                        Email1=Email1,
                        Email2=Email2,
                        Phone=Phone,
                        Linkedin_URL=Linkedin_URL,
                        Contact_Status=Contact_Status,
                        New_Lead_Source=New_Lead_Source,
                        Services=Services,
                        Products=Products,
                        Mailing_City=Mailing_City,
                        Mailing_State=Mailing_State,
                        Mailing_Country=Mailing_Country,
                        Region=Region,
                        Campaigns_targetted=Campaigns_targetted,
                        Email_Valid=Email_Valid,
                        Last_Targetted=Last_Targetted)
            db.session.add(data)
            db.session.commit()
            flash('Congratulations, entry added!')
            return redirect(url_for('index'))
    # return redirect(url_for('admin'))
    # return 'inside now 1'

        return render_template('ContactData.html',
                               title='ContactData',
                               form=form)
    else:
        return 'not admin'