def load_model(): from app import r if request.method == 'GET': rv = r.get('_model') return jsonify(model=rv, success=True), 200 r.set('_model', reuest.data) return jsonify(success=True), 200
def pid_tunning(): ''' s = r.get('plot_script') d = r.get('plot_div') if s and r: script, div = s.decode('utf-8'), d.decode('utf-8') cdn_js = [] while r.llen('plot_cdn') > 0: cdn_js.append(r.lpop('plot_cdn').decode('utf-8')) else: ''' script, div, cdn_js = plot() r.set('plot_script', script) r.set('plot_div', div) #for cdn in cdn_js: #r.rpush('plot_cdn', cdn) return render_template('pid_tunning.html', script=script, div=div, cdn_js=cdn_js)
def setup_method(self, method): app.testing = True self.client = app.test_client() for i in range(1000): r.zadd('treasures', i, i) r.set('listings.%s.data' % i, json.dumps({ 'listing_id': i, 'quantity': i, 'materials': [], 'views': i, 'url': 'http://google.com', 'title': 'HEllo', 'Images': [ {'url_170x135': 'http://google.com'}, ], 'price': 123, 'currency_code': 'USD', 'Shop': {'shop_name': 'Heollo', 'url': 'http://google.com'}, 'users': 10, }))
def index(): rez = r.get("topstudent") ti = '' data = None top_grade = [] if not rez: top_grade = list(Grade.objects().aggregate(*[{ "$group": { "_id": { "student": "$student", "course": "$course" }, "avggrade": { "$avg": "$grade" } } }, { "$sort": { "avggrade": -1 } }, { "$limit": 1 }])) if top_grade: student_db = Student.objects.get(id=top_grade[0]["_id"]["student"]) top_grade[0]["name"] = student_db.firstName top_grade[0]["lname"] = student_db.lastName course_db = Course.objects.get(id=top_grade[0]["_id"]["course"]) s = json.dumps(top_grade[0], indent=4, sort_keys=True) r.set("topstudent", s) r.expire('topstudent', 30) rez = r.get("topstudent") ti = json.dumps(MongoEngineJSONEncoder(course_db), indent=4, sort_keys=True) data = json.loads(rez) return render_template("index.html", top_student=data, loaded=ti)
def index(): if request.method == 'GET': return render_template('index.html') elif request.method == 'POST': # ipdb.set_trace() filename = request.form['filename'] passwd = request.form['pass'] # ipdb.set_trace() try: # check if file already exists # if doesnt exists then create a new file and enter details in redis if not r.exists(filename) or r.exists == None: r.hmset(filename,{request.remote_addr:filename}) r.set(filename+'pass',passwd) a=soldier.run('touch app/files/' + filename) # start queue for sending data to clients start_queue(filename) # if exists check for password else: if r.exists(filename+'pass'): if r.get(filename+'pass')!=passwd: return redirect('/') except: # exception will be if file is not present hence create the file r.hmset(filename,{request.remote_addr:filename}) r.set(filename+'pass',passwd) a=soldier.run('touch app/files/' + filename) # start queue for sending data to clients start_queue(filename) if r.get(filename+'pass')!=passwd: return redirect('/') # add filename to curr ip and vice versa in redis ip_file_map = r.hgetall(filename) ip_file_map[request.remote_addr] = filename r.hmset(filename,ip_file_map) r.set(request.remote_addr, filename) # store that user is logged in session['logged_in'] = filename return redirect('/edit/' + filename)
def store_fake_data(listing_id, score=9000): """Stores fake listing data for listing_id.""" r.set('listings.%s.data' % listing_id, '{"hello": "there"}') r.sadd('listings.%s.users' % listing_id, '999') r.zadd('treasures', listing_id, score)
def __setitem__(self, key, value): if isinstance(value, Model): # If the value is a model , use the id value = value.id return redis.set(self.__keytransform__(key), value)
def save_listing(listing): """Save a listing.""" r.set("listings.%s.data" % listing["listing_id"], json.dumps(listing))