Esempio n. 1
0
def run_simulation_callback(n_clicks, simulation_days):
    print('run simulation (days %d)' % simulation_days)
    print(generate_cache_key(simulate_individuals))
    set_variable('simulation_days', simulation_days)
    if n_clicks:
        set_variable('random_seed', n_clicks)

    df = simulate_individuals(only_if_in_cache=True)
    if df is not None:
        return render_results(df)

    if settings.RESTRICT_TO_PRESET_SCENARIOS:
        return [html.Div('Palvelussa ruuhkaa, osa simulaatiotoiminnallisuuksista on pois käytöstä')]

    existing_thread_id = session.get('thread_id', None)
    if existing_thread_id:
        cache.set('thread-%s-kill' % existing_thread_id, True)

    process = SimulationThread(variables=session.copy())
    session['thread_id'] = process.uuid
    process.start()

    return [
        dcc.Interval(id='simulation-output-interval', interval=500, max_intervals=60),
        html.Div(id='simulation-output-results'),
    ]
Esempio n. 2
0
def integration_home():
    session_ = session.copy()
    if "_ucam_webauth" in session_:
        del session_["_ucam_webauth"]
    if "_flashes" in session_:
        del session_["_flashes"]
    return render_template("integration.html", session=session_)
Esempio n. 3
0
def integration_home():
    session_ = session.copy()
    if "_ucam_webauth" in session_:
        del session_["_ucam_webauth"]
    if "_flashes" in session_:
        del session_["_flashes"]
    return render_template("integration.html", session=session_)
Esempio n. 4
0
def run_simulation_callback(n_clicks, simulation_days):
    from flask import session
    from common import cache

    print('run simulation (days %d)' % simulation_days)
    set_variable('simulation_days', simulation_days)
    if n_clicks:
        set_variable('random_seed', n_clicks)

    df = simulate_individuals(only_if_in_cache=True)
    if df is not None:
        return render_results(df)

    existing_thread_id = session.get('thread_id', None)
    if existing_thread_id:
        cache.set('thread-%s-kill' % existing_thread_id, True)

    process = SimulationThread(variables=session.copy())
    session['thread_id'] = process.uuid
    process.start()

    return [
        dcc.Interval(id='simulation-output-interval',
                     interval=500,
                     max_intervals=60),
        html.Div(id='simulation-output-results'),
    ]
Esempio n. 5
0
def user_logout():
    tmp = session.copy()
    for i in tmp:
        del (session[i])

    del tmp

    session['login'] = False

    return redirect(url_for('user.user_login'))
Esempio n. 6
0
def getmapNewuser():
    result_df = pd.DataFrame()
    if session.get('keyword') != None:
        result_df = getKeyWordsRecoms(session.get('keyword'), 5).toPandas()
        for key in session.copy():
            session.pop(key, None)
    mp = folium.Map(location=[36.1699, -115.1398], zoom_start=12)
    for i, r in result_df.iterrows():
        folium.Marker(location=[float(r.latitude),
                                float(r.longitude)],
                      popup=html.escape(r["business_name"]) + '<br>' +
                      'Stars: ' + str(r.stars) + '<br>' + 'Reviews: ' +
                      str(r.review_count),
                      icon=folium.Icon(color='green')).add_to(mp)
    return mp._repr_html_()
Esempio n. 7
0
def create_session(username=None, staff=False):
	try:
		sess = sessions.get(request.remote_addr)
		if "username" in sess:
			return jsonify(error={"message": "SESSION ALREADY HAS ID/USERNAME"})
	except:
		pass

	if username is None:
		username = request.json.get("username")

	session["username"] = username
	session["staff"] = staff
	sessions[request.remote_addr] = session.copy()
	return jsonify(data={"session_id" : session["username"], "staff" : session["staff"]})
Esempio n. 8
0
    def create_test_client(self, user):
        """ Create a test client with the permissions and an active session of the given user. """
        with self.app.test_request_context():
            db.session.add(user)
            db.session.commit()

            # Login the user and save the session
            login_user(user)
            session_copy = session.copy()

        # Re-create the session with a new test client
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                for k, v in session_copy.items():
                    sess[k] = v
            return c
Esempio n. 9
0
    def create_test_client(self, user):
        """ Create a test client with the permissions and an active session of the given user. """
        with self.app.test_request_context():
            db.session.add(user)
            db.session.commit()

            # Login the user and save the session
            login_user(user)
            session_copy = session.copy()

        # Re-create the session with a new test client
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                for k, v in session_copy.items():
                    sess[k] = v
            return c
Esempio n. 10
0
def logged_in_user(db):
    app = create_app(TestConfig)
    user = User(username='******', email='*****@*****.**')
    with app.test_request_context():
        db.session.add(user)
        db.session.commit()

        # Login the user and save the session
        login_user(user)
        session_copy = session.copy()

    # Re-create the session with a new test client
    with app.test_client() as c:
        with c.session_transaction() as sess:
            for k, v in session_copy.items():
                sess[k] = v
        return c
Esempio n. 11
0
    def deco_func(*args, **kwargs):
        try:
            session_key = request.cookies.get(app.config['SESSION_COOKIE_NAME'])

            is_login = False
            print str(session.sid) + " == " + str(session_key) + " : " + str(session.sid == session_key)
            print 'session.__contains__("userid") : ' + str(session.copy())
            if session.sid == session_key and session.__contains__('userid'):
                is_login = True

            if not is_login:
                print '로그인 필요'
                flash("login please.")
                return redirect('/')

            return f(*args, **kwargs)
        except Exception as e:
            print '에러 : ' + str(e)
            raise e
Esempio n. 12
0
    def mutate(root, info, random_seed=None):
        variables = session.copy()
        if random_seed is not None:
            variables['random_seed'] = random_seed

        for key, process in list(simulation_processes.items()):
            if process.exitcode is not None:
                process.join()
                del simulation_processes[key]

        if len(simulation_processes) >= 16:
            raise GraphQLError('System busy')

        process = SimulationProcess(variables=variables)
        run_id = process.cache_key
        process.start()
        if process.pid:
            print('Started process with PID %s (key %s)' % (process.pid, process.cache_key))
            simulation_processes[process.cache_key] = process

        return dict(run_id=run_id)
Esempio n. 13
0
def pubsub():
    print("pubsub in.")
    p = r.pubsub()
    p.subscribe(['device'])
    cache = {}
    print("first cache:%s" % cache)

    def get_data(s, cache):
        print("get_data in.")
        for item in p.listen():
            print(item)
            if item['type'] == 'message':
                data = item['data']
                ds = hash_message(data.decode('utf8'))
                if 'ret' in ds:
                    if ds['ret'] == 'error':
                        if ds['state'] == 'using' and ds['user'] == s['id']:
                            print('user:    %s' % ds['user'])
                            break
                cache['ret'] = 'success'
                yield 'data:%s\n\n' % data
        cache['ret'] = "error"
        cache['msg'] = "using"
        print("get_data out.")
        yield 'data:%s\n\n' % "the device is using."

    tmp = session.copy()
    resp = get_data(tmp, cache)
    next(resp)
    print(cache)
    if 'ret' in cache:
        print(cache['ret'])
        if cache['ret'] == 'error':
            print('ret:%s' % cache['ret'])
            p.unsubscribe('device')
            return make_response("%s" % cache['ret'])
    print("pubsub out.")
    return Response(resp, mimetype="text/event-stream")
Esempio n. 14
0
def index():
    for key in session.copy():
        session.pop(key, None)
    return render_template('index.html')
Esempio n. 15
0
	
	* 判断是否存在
		'name' in session
	
	* 获取数据
		session['name']
		* 如果数据不存在,抛出异常 KeyError
	
	* session部分方法
		session.get(name,default)
			* 安全的取值
		session.keys()
		session.values()
		session.items()
		session.fromkeys()
		session.copy()
		session.clear
	

	* session属性
		new
			* 如果会话是新的,则该值为 True

		modified
			* session是否被修改(进行了CUD)
			* 如果是对session里面的对象,进行修改,该值不会发生变化,需要手动的修改该值
				session['objects'].append(42)
				session.modified = True
		permanent
			* 如果设置为True,则会话持续app.permanent_session_lifetime秒.默认值为31天
			* 如果设置为False(这是默认值),当用户关闭浏览器时,会话将被删除
Esempio n. 16
0
def remove_session():
    # the dictionary needs to be copied to avoid a runtime error
    sess = login_session.copy()
    for (key, value) in sess.items():
        del login_session[key]
Esempio n. 17
0
def reset_session():
    for key in session.copy():
        if key != 'csrf_token':
            del session[key]
            session.updated = True
Esempio n. 18
0
def only_memeber():
    return '회원만 접근가능한 페이지 입니다.' + session.get('userid')+ '님 반갑습니다. <br> 세션 만료시간 : '+ str(session.copy())
Esempio n. 19
0
def map():
    session_ = session.copy()
    return render_template("map.html", session=session_)