def upload(request): name = "" if request.method == 'POST' and request.POST.get('search', "") == "": context = {} form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newDoc = Document(docfile=request.FILES.get('docfile', "")) name = form.cleaned_data['docfile'].name newDoc.save() documents = Document.objects.all() if name != "": location = "../media/uploads/" + name s = convert_video_to_frame(cwd + "/media/uploads/" + name) sorted_inverted = model_to_inverted_index(s) print sorted_inverted convert_from_mili(sorted_inverted) val = 1 if len(Index.objects.filter()) > 0: val = len(Index.objects.filter()) + 1 b = Index(invertedIndex=json.dumps(sorted_inverted), name=name, video_id=val, images=json.dumps(s)) vid_id = b.video_id b.save() return redirect("/video/%s" % vid_id) return render(request, 'home.html', context) if request.method == 'GET': return render(request, 'upload.html')
def _getIndices(self, xml): if xml.nodeName != "table": raise ValueError("Is not a table") indexes = [] for index in xml.getElementsByTagName("index"): tmp = Index() if index.hasChildNodes(): for item in index.getElementsByTagName("item"): pass else: item = Item() item.name = index.getAttribute("field") tmp.fields.append(item.name) for attributeName, attributeValue in index.attributes.items(): if attributeName.lower() == "field": pass elif attributeName.lower() == "props": for prop in attributeValue.split(", "): if prop == "fulltext": tmp.fulltext = True elif prop == "uniqueness": tmp.uniqueness = True else: raise ValueError( "Invalid format of props string: {}".format( attributeValue)) else: raise ValueError( "Incorrect attribute name \"{}\" in tag \"{}\" ". format(attributeName, index.nodeName)) indexes.append(tmp) return indexes
def _getDbIndices(self, cur, table_id): indices = [] db_indices = cur.execute( """ SELECT * from dbd$indices WHERE table_id = :id""", { "id": table_id }).fetchall() for index in db_indices: tmp = Index() for item in self._getDbIndexDetails(cur, index[0]): tmp.fields.append(item.name) if index[2] is not None: tmp.name = str(index[2].encode('utf-8')) tmp.fulltext = index[3] if index[4] != "simple": tmp.uniqueness = index[4] indices.append(tmp) return indices
def index(): form2 = IndexForm() # if 'email' in session: # return redirect(url_for('profile')) if request.method == 'POST': newindex = Index(form2.index1.data, form2.index2.data, form2.index3.data, form2.index4.data) db.session.add(newindex) db.session.commit() print "see something?" return redirect(url_for('profile')) elif request.method == 'GET': return render_template('index.html', form=form2)
def app_init(): info = {Activities.init_db(), Index.init_db(), Payments.init_db()} return "Activities, Index, Payments databases re-initialized"
from models import (Users, Activities, EventLogger, Utility, Webhooks, Index, Payments, db_sql, mongodb, redis) # initialize MongoDB collections if necessary collections = mongodb.collection_names() if "history" not in collections: EventLogger.init() if Activities.name not in collections: Activities.init_db() else: Activities.update_ttl() if Index.name not in collections: Index.init_db() else: Index.update_ttl() if Payments.name not in collections: Payments.init_db() Analytics(app) def parseInt(s): try: return int(s) except ValueError: return
def api_register_index(request): apikey = request.GET['api_key'] index_name = request.GET['index_name'] try: account = Account.objects.get(apikey=apikey) except Account.DoesNotExist: #@UndefinedVariable return HttpResponse('{"status":"ERROR", "message":"Invalid account"}') if len(account.indexes.all()) >= account.package.max_indexes: return HttpResponse( '{"status":"ERROR", "message":"Account limit reached"}') else: index = Index() index.populate_for_account(account) index.name = index_name index.creation_time = datetime.datetime.now() index.language_code = 'en' try: index.save() except IntegrityError, ie: print('integrityError in api_register_index.', ie) return HttpResponse( '{"status":"ERROR", "message":"You already have and Index with that name or code."}' ) index.base_port = STARTING_BASE_PORT + 10 * index.id index.code = get_index_code(index.id) index.save() start_index(index) response = '{"status":"OK", "index_code":"%s"}' % (index.code) return HttpResponse(response)
def add_ticker(self, ticker, name=None, exchange=None, timezone=None, index=None, sector=None, industry=None, start=None, end=None): ''' Add the symbol to either Index or Equity table and populate quotes table with all available historical quotes. If any of the optional parameters are left out, the corresponding information will be obtained from Yahoo! Finance. :param ticker: Stock ticker symbol :param name: (optional) Company/security name :param exchange: (optional) Exchange on which the security is traded :param sector: (optional) Company/security sector :param Industry (optional) Company/security industry ''' ticker = ticker.lower() session = self.db.Session() if self.check_ticker_exists(ticker, session): log.warn("Stock {} already exists!".format((ticker.upper()))) return #TODO Add start and end date in it ## Shared informations if name is None: name = quotes.get_name(ticker) if exchange is None: exchange = quotes.get_stock_exchange(ticker) # Check if we have an index symbol if ticker.find('^') == 0: timezone = 'US/Eastern' stock = Index(ticker, name=name, exchange=exchange, timezone=timezone) else: if index is None: index = quotes.get_indices(ticker) if sector is None: sector = quotes.get_sector(ticker) if industry is None: industry = quotes.get_industry(ticker) stock = Equity(ticker, name, exchange, index, sector, industry) session.add(stock) if start is None: log.info('Reading NeuronQuant MySQL configuration...') sql = json.load( open( '/'.join( (os.path.expanduser('~/.quantrade'), 'default.json')), 'r'))['mysql'] start = datetime.strptime(sql['data_start'], '%Y-%m-%d').date() if end is None: end = date.today() q = self._download_quotes(ticker, start, end) session.add_all(q) session.commit() session.close()
def index(): index = Index(title='Index', content="Hello, Flask!") return render_template("index.html", index=index)
def dataManage(): if request.method == 'GET': return render_template('dataManage.html') else: schoolName = request.form.get('schoolName') year = (request.form.get('year')) province = request.form.get('province') city = request.form.get('city') county = request.form.get('county') sumStu = int(request.form.get('sumStu')) schoolPut = float(request.form.get('schoolPut')) studentAvg = float(request.form.get('studentAvg')) computerSum = int(request.form.get('computerSum')) multiClass = int(request.form.get('multiClass')) classSum = int(request.form.get('classSum')) broadband = float(request.form.get('broadband')) broadbandAvg = float(request.form.get('broadbandAvg')) effectPrepare = float(request.form.get('effectPrepare')) pertinencePrepare = float(request.form.get('pertinencePrepare')) optimizeTeach = float(request.form.get('optimizeTeach')) turnoverTeach = float(request.form.get('turnoverTeach')) manageCourse = float(request.form.get('manageCourse')) communicateCourse = float(request.form.get('communicateCourse')) # 投入指数 if (schoolPut/sumStu)/studentAvg > 1: I = 1 else: I = round((schoolPut/sumStu)/studentAvg,2) C1 = round(computerSum/sumStu,2) C2 = round(multiClass/classSum,2) if broadband >= 1000: C3 = 1.0 elif broadband >= 100: C3 = 0.5 elif broadband > 0: C3 = 0.2 else: broadband = 0 # 配置指数 C = round((C1*C2*C3) ** (1./3),2) E1 = round(0.67*effectPrepare+0.33*pertinencePrepare,2) E2 = round(0.33*optimizeTeach+0.67*turnoverTeach,2) E3 = round(0.67*manageCourse+0.33*communicateCourse,2) # 效果指数 E = round((E1*E2*E3) ** (1./3),2) # 总指数 final_index = round((I**0.25)*(C**0.25)*(E**0.5),2) # print(final_index) index = Index(schoolName=schoolName,year=year,schoolProvince=province,schoolCity=city,schoolCounty=county,schoolStu=sumStu,schoolPut=schoolPut,studentAvg=studentAvg,computerSum=computerSum,multiClass=multiClass,classSum=classSum,broadband=broadband,broadbandAvg=broadbandAvg,effectPrepare=effectPrepare,pertinencePrepare=pertinencePrepare,optimizeTeach=optimizeTeach,turnoverTeach=turnoverTeach,manageCourse=manageCourse,communicateCourse=communicateCourse,I=I,C1=C1,C2=C2,C3=C3,C=C,E1=E1,E2=E2,E3=E3,E=E,final_index=final_index) db.session.add(index) db.session.commit() user_id = session.get('user_id') user = User.query.filter(User.id == user_id).first() person_add = Person_add(author_id=user.id,index_id=index.id) db.session.add(person_add) db.session.commit() return redirect(url_for('dataModification'))
def api_register_index(request): apikey = request.GET['api_key'] index_name = request.GET['index_name'] try: account = Account.objects.get(apikey=apikey) except Account.DoesNotExist: #@UndefinedVariable return HttpResponse('{"status":"ERROR", "message":"Invalid account"}') if len(account.indexes.all()) >= account.package.max_indexes: return HttpResponse('{"status":"ERROR", "message":"Account limit reached"}') else: index = Index() index.populate_for_account(account); index.name = index_name index.creation_time = datetime.datetime.now() index.language_code = 'en' try: index.save() except IntegrityError, ie: print('integrityError in api_register_index.', ie) return HttpResponse('{"status":"ERROR", "message":"You already have and Index with that name or code."}') index.base_port = STARTING_BASE_PORT + 10 * index.id index.code = get_index_code(index.id) index.save() start_index(index) response = '{"status":"OK", "index_code":"%s"}' % (index.code) return HttpResponse(response)
DOWNLOADS_PROCESSOR_NAME_FILTER = [re.compile(s) for s in ["Unassigned", "^Out of", "Recovered"]] DOWNLOADS_PROCESSOR_NAME_REPLACEMENTS = { 'US': 'United States', 'Korea, South': 'South Korea', 'Taiwan*': 'Taiwan', 'Bonaire, Sint Eustatius and Saba': 'Bonaire/Sint Eustatius/Saba', 'District of Columbia, District of Columbia': 'District of Columbia', 'District of Columbia,District of Columbia': 'District of Columbia' } """ MONGO """ MONGO_CONNECTION_STR = "mongodb://%s:%s@%s:%s" % (DB_USER, DB_PASS, DB_HOST, DB_PORT) MONGO_INDEXES = [ Index("regions", "name", pymongo.HASHED), Index("regions", "parent_id", pymongo.HASHED), Index("locations", "region_id", pymongo.HASHED), Index("locations", "geo", pymongo.GEOSPHERE), Index("series", "name", pymongo.HASHED), Index("data", "location.regions", pymongo.ASCENDING), Index("demographics", "region_id", pymongo.HASHED), Index("facts", "region_id", pymongo.HASHED), Index("contacts", "region_id", pymongo.HASHED) ] """ GOOGLE API """ GOOGLE_API_GEOCODE_COORD_URL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=false&key=%s" GOOGLE_API_GEOCODE_ADDR_URL = "https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false&key=%s"