コード例 #1
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def delete_item(_id):
    """ deletes a bucketlist and its items"""
    index_ = Data.get_index(_id, Data.items)
    b_id = Data.items[index_]['owner_id']
    Data.delete_dictionary(_id, Data.items)
    flash('Item deleted', 'Danger')
    return redirect(url_for('bucketlist_items', _id=b_id))
コード例 #2
0
def data_by_name(name="Canada") -> Data:
    response = get(url=CANADA_HEALTH)
    records = list(
        csv.reader(response.content.decode("utf-8").splitlines(), delimiter=",")
    )
    data = Data(name)
    prev_record = {}
    for (index, record) in enumerate(records):
        if record[1] == name:
            for (record_index, field) in enumerate(record):
                if field in ["", "N/A"]:
                    if index == 0:
                        record[record_index] = 0
                        prev_record.update({record_index: 0})
                    else:
                        if record_index not in prev_record:
                            prev_record.update({record_index: 0})
                        record[record_index] = prev_record[record_index]
                else:
                    prev_record.update({record_index: field})

            data.add_record(
                Record(
                    date=record[3],
                    confirmed_cases=record[4],
                    probable_cases=record[5],
                    deaths=record[6],
                    tested=record[8],
                    recoveries=record[9],
                )
            )
    return data
コード例 #3
0
def dashboard(user_id, sensor_id):
    data = []
    labels = []
    sensor_query = Sensors.objects(user=session.get('user'), id=sensor_id)

    if request.method == 'POST':
        data = []
        labels = []
        data_day = Data.objects(user=session.get('user'),
                                name_sensor=sensor_query[0]['name_sensor'],
                                day=request.form['day'])

        for data_q in data_day:
            data.append(data_q.value)
            labels.append(data_q.hour)
        flash(
            'Exibindo %i resultados para %s' %
            (len(data_day), request.form['day']), 'info')
        return render_template('sensors/dashboard.html',
                               sensor=sensor_query[0],
                               data=data,
                               labels=labels)

    data_query = Data.objects(
        user=session.get('user'),
        name_sensor=sensor_query[0]['name_sensor']).limit(750)

    for data_q in data_query:
        data.append(data_q.value)
        labels.append(data_q.hour)

    return render_template('sensors/dashboard.html',
                           sensor=sensor_query[0],
                           data=data,
                           labels=labels)
コード例 #4
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def delete_bucketlist(_id):
    """ deletes a bucketlist and its items"""
    Data.delete_dictionary(_id, Data.bucketlists)
    all_items = Data.get_the_data(_id, Data.items)
    if all_items is not None:
        for item in all_items:
            if item['_id'] in Data.items:
                Data.delete_dictionary(item['_id'], Data.items)
    flash('Bucketlist deleted', 'Danger')
    return redirect(url_for('dashboard'))
コード例 #5
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def bucketlist_items(_id):
    """method used for displaying a bucketlists items"""
    page_title = "Items"
    bucketlist_ = Data.get_the_data(_id, Data.bucketlists)
    items = Data.get_the_data(_id, Data.items)
    notify = 'You have no items in this bucketlist yet'
    return render_template('items.html',
                           items=items,
                           notify=notify,
                           bucketlist_=bucketlist_,
                           title=page_title)
コード例 #6
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def dashboard():
    """method for displaying users bucketlists"""
    page_title = "Dashboard"
    bucketlists = Data.get_the_data(session['id'], Data.bucketlists)
    notify = 'You have no bucketlists yet'
    return render_template('dashboard.html',
                           bucketlists=bucketlists,
                           notify=notify,
                           username=session['username'],
                           title=page_title)
コード例 #7
0
ファイル: user.py プロジェクト: justmesam/Bucketlist_app
 def create_item(_id, item_name, description):
     """method used to create bucketlist items"""
     data_ = Data.get_the_data(_id, Data.bucketlists)
     for data in data_:
         bucketlist = Bucketlist(data['title'],
                                 data['owner'],
                                 data['intro'],
                                 data['owner_id'],
                                 data['_id'])
         bucketlist.new_item(item_name=item_name,
                             description=description)
コード例 #8
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def edit_bucketlist(_id):
    """method lets the user  edit existing buckelists"""
    page_title = "Edit"
    index_ = Data.get_index(_id, Data.bucketlists)
    form = TextForm(request.form)

    form.title.data = Data.bucketlists[index_]['title']
    form.body.data = Data.bucketlists[index_]['intro']

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        intro = request.form['body']
        Data.bucketlists[index_]['title'] = title
        Data.bucketlists[index_]['intro'] = intro
        flash('Your Bucketlist has been updated', 'success')
        return redirect(url_for('dashboard'))
    return render_template('create.html', form=form, title=page_title)
コード例 #9
0
ファイル: views.py プロジェクト: justmesam/Bucketlist_app
def edit_bucketlist_item(_id):
    """method lets the user  edit existing buckelists"""
    page_title = "Edit"
    index_ = Data.get_index(_id, Data.items)
    form = TextForm(request.form)

    #    ### populating the form for user to edit ###

    form.title.data = Data.items[index_]['item_name']
    form.body.data = Data.items[index_]['description']

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        intro = request.form['body']
        Data.items[index_]['item_name'] = title
        Data.items[index_]['description'] = intro
        flash('Your Item has been updated', 'success')
        return redirect(
            url_for('bucketlist_items', _id=Data.items[index_]['owner_id']))
    return render_template('add_item.html', form=form, title=page_title)
コード例 #10
0
def submit_confirm():
    form = request.form
    print form
    marker = form["marker"].upper()
    station = Station.query.filter_by(name=marker).first()
    if station is not None and station.online:
        try:
            point = Data(water_level=float(form["water_level"]),
                         water_clarity=int(form["clarity_value"]))
            station.data_points.append(point)
            db.session.commit()
            return render_template("submit_confirm.html",
                                   water_level=form["water_level"],
                                   station=marker,
                                   water_clarity=form['clarity_value'])
        except ValueError:
            return render_template("submit.html",
                                   error='The measurement entered was formatted incorrectly. Make sure you only use numbers.'), 400
    else:
        return render_template("submit.html",
                               error="No location "+marker+". Please verify the marker ID and resubmit."), 400
コード例 #11
0
def run():
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    DESK_COUNT = 2
    SKELETON_COUNT = 20
    SPECIALIST_COUNT = size - 1
    JOBS = 30

    if rank == 0:
        generator(comm, size, JOBS)

    else:
        data = Data(rank, SKELETON_COUNT, SPECIALIST_COUNT, DESK_COUNT)
        # handlers init
        awaiting_job_handler = AwaitingJobHandler(
            comm=comm, data=data, state=State.AWAITING_JOB)
        requesting_job_handler = RequestingJobHandler(
            comm=comm, data=data, state=State.REQUESTING_JOB)
        awaiting_partners_handler = AwaitingPartnersHandler(
            comm=comm, data=data, state=State.AWAITING_PARTNERS)
        awaiting_desk_handler = AwaitingDeskHandler(
            comm=comm, data=data, state=State.AWAITING_DESK)
        awaiting_start_handler = AwaitingStartHandler(
            comm=comm, data=data, state=State.AWAITING_START)
        paper_work_handler = PaperWorkHandler(
            comm=comm, data=data, state=State.PAPER_WORK)
        acquire_skeleton_handler = AcquireSkeletonHandler(
            comm=comm, data=data, state=State.ACQUIRE_SKELETON)
        reviving_handler = RevivingHandler(
            comm=comm, data=data, state=State.REVIVING)

        # main loop
        data.state = State.AWAITING_JOB
        while True:
            status = MPI.Status()
            msg = comm.recv(source=MPI.ANY_SOURCE,
                            tag=MPI.ANY_TAG, status=status)
            tag = status.Get_tag()
            source = status.Get_source()

            data.timestamp = max(data.timestamp, msg['timestamp']) + 1

            if tag == Message.NEW_JOB:
                data.job_map[msg['job_id']] = 0
                data.partners[msg['job_id']] = []
                awaiting_job_handler.log(
                    f'Got NEW_JOB with job_id = {msg["job_id"]}', [Message.NEW_JOB])
            elif tag == Message.HELLO:
                data.partners[msg['job_id']].append(source)
                awaiting_job_handler.log(
                    f'Got HELLO from {source} for job_id = {msg["job_id"]}', [Message.HELLO])
            elif tag == Message.SKELETON_TAKEN:
                data.skeleton_count -= 1
                awaiting_job_handler.log(f'Got SKELETON_TAKEN from {source}. Decrementing skeleton count to {data.skeleton_count}', [
                                         Message.SKELETON_TAKEN])

            if data.state == State.AWAITING_JOB:
                awaiting_job_handler(msg=msg, status=status)
            elif data.state == State.REQUESTING_JOB:
                requesting_job_handler(msg=msg, status=status)
            elif data.state == State.AWAITING_PARTNERS:
                awaiting_partners_handler(msg=msg, status=status)
            elif data.state == State.AWAITING_DESK:
                awaiting_desk_handler(msg=msg, status=status)
            elif data.state == State.PAPER_WORK:
                paper_work_handler(msg=msg, status=status)
            elif data.state == State.ACQUIRE_SKELETON:
                acquire_skeleton_handler(msg=msg, status=status)
            elif data.state == State.AWAITING_START:
                awaiting_start_handler(msg=msg, status=status)
            elif data.state == State.REVIVING:
                reviving_handler(msg=msg, status=status)
コード例 #12
0
ファイル: user.py プロジェクト: justmesam/Bucketlist_app
 def save_to_users(self):
     """this method saves the user to users"""
     Data.add_data(self.user_data())
コード例 #13
0
def save_data(msg):
    data = Data()
    data.user = msg.get('user')
    data.local = msg.get('local')
    data.device = msg.get('device')
    data.day = msg.get('day')
    data.hour = msg.get('hour')
    data.name_sensor = msg.get('name_sensor')
    data.type_sensor = msg.get('type_sensor')
    data.model_sensor = msg.get('model_sensor')
    data.value = msg.get('value')
    data.save()
コード例 #14
0
 def save_to_items(self):
     """this method saves data to the item list"""
     Data.add_data(self.item_data())
コード例 #15
0
 def save_to_bucketlists(self):
     """this methods saves data to the bucketlists list"""
     Data.add_data(self.bucketlist_data())