def copyrightManuDis(self, pProj=0): """ 展示版权说明 """ self.show_panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) modelinfo = Sql.selectSql(args=(pProj, ), sql=Sql.selectModel) title = u"版权说明" + u'(模型:' + modelinfo[0][0] + ')' self.AddPage(self.show_panel, title, True, wx.NullBitmap) show_panel = self.show_panel show_panel.pid = pProj show_panel.params = Sql.selectSql((pProj, ), Sql.selectParams) # show_panel 的布局,只有 scrollPanel 一个元素 show_panel.bSizer = wx.BoxSizer(wx.VERTICAL) # 为实现滚动条加入 scrollPanel show_panel.scrolledWindow = wx.ScrolledWindow(show_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL | wx.VSCROLL) show_panel.scrolledWindow.SetScrollRate(5, 5) scrollPanel = show_panel.scrolledWindow # scrollPanel 的布局,元素为显示的控件 show_panel.gbSizer = wx.GridBagSizer(5, 5) show_panel.gbSizer.SetFlexibleDirection(wx.BOTH) show_panel.gbSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) # show_panel布局设置 scrollPanel.SetSizer(show_panel.gbSizer) scrollPanel.Layout() show_panel.bSizer.Add(scrollPanel, 1, wx.EXPAND | wx.ALL, 5) show_panel.SetSizer(show_panel.bSizer) show_panel.Layout() show_panel.Bind( wx.EVT_SIZE, lambda evt, show_panel=show_panel: self.OnReSize(evt, show_panel))
def ClickImport2(self, event): show_panel = self.GetCurrentPage() proj_name = show_panel.textCtrl1.GetValue() proj_descr = show_panel.textCtrl2.GetValue() if proj_name == '': return # record = Sql.selectSql((proj_name, show_panel.pid), Sql.selectProj) # if record != []: # show_panel.staticText3.Show(show=True) # show_panel.Layout() # return show_panel.staticText3.Show(show=False) dlg = wx.DirDialog(self, u"选择文件夹", style=wx.DD_DEFAULT_STYLE) if dlg.ShowModal() == wx.ID_OK: Sql.deleteSql(args=(show_panel.old_id, ), sql=Sql.deleteFile) """重新导入模型,新id变化""" show_panel.new_id = Import_file.insert_blob( proj_name, show_panel.pid, proj_descr, dlg.GetPath(), show_panel.old_id) show_panel.dir_text.SetValue(dlg.GetPath()) show_panel.dir_text.Disable() show_panel.button1.Disable() self.clearControl(show_panel) self.genInParams(show_panel.new_id, show_panel) dlg.Destroy()
def pub_form(): status = '' if "u_name" in session: if request.method == 'POST': image = request.files['pic'] ISSN = request.form['ISSN'] Title = request.form['Title'] UNITS = request.form['unit'] #'TYPE_':request.form['type'], #DATE_=request.form['date'] PRICE = request.form['Price'] TYPE_ = request.form['type'] IMAGE_name = secure_filename(image.filename) status = Sql.insert_data(ISSN, Title, UNITS, PRICE, IMAGE_name, session['u_name']) image.save( os.path.join(app.config['UPLOAD_IMAGE'], session['u_name'], secure_filename(image.filename))) status1 = Sql.insert_data1(TYPE_, ISSN, session['u_name']) return render_template("pub_form.html", val=session['u_name'], return_=status) return render_template("pub_form.html", val=session['u_name'], return_=status)
def signup(): if request.method == 'POST': u_name = request.form['email'] name = request.form['name'] password = request.form['password'] ADDRESS = request.form['ADDRESS'] P_NO = request.form['P_NO'] type_ = request.form['optradio'] print(type_) db_ = 'yt' if type_ == 'Publishers': db_ = 'Publishers' else: db_ = 'Subscriber' f_path = os.path.join(app.config['UPLOAD_IMAGE'], u_name) os.mkdir(f_path) value = Sql.insert_(u_name, name, password, db_, ADDRESS) if type_ == 'Publishers': value1 = Sql.insert_1(u_name, P_NO) else: value2 = Sql.insert_2(u_name, P_NO) print('dscbshdcb') return redirect('/') else: return render_template("signup.html")
def tea(): #老师获取所有的考勤记录,并且用申请请假覆盖未到状态 sql = Sql() tes = sql.select('work', whe={'date': now()}) for i in range(0, len(tes)): if sql.get('apply', whe={ 'date': tes[i][2], 'uid': tes[i][3] }) is not None: tes[i] = list(tes[i]) tes[i][4] = -2 return tes
def final_pay(cou): if "u_name" in session: if request.method == 'POST': CARD_NO = request.form['CARD_NO'] status = Sql.subscription(cou, CARD_NO, u_name=session['u_name']) end = Sql.end_page(u_name=session['u_name']) return render_template("end_page.html", u_name=session['u_name'], end1=end) return render_template("plan.html", u_name=session['u_name'])
def ClickModelDelete(self, event): dlg = wx.MessageBox("确认删除该模型", "提示", wx.OK | wx.ICON_INFORMATION | wx.CANCEL) if dlg == 4: n_id = self.navTree.GetItemData(self.navTree.GetSelection()) Sql.deleteSql(args=(n_id, ), sql=Sql.deleteSamplingResult) Sql.deleteSql(args=(n_id, ), sql=Sql.deleteModelArgs) Sql.deleteSql(args=(n_id, ), sql=Sql.deleteModelOutputArgs) Sql.deleteSql(args=(n_id, ), sql=Sql.deleteFile) Sql.deleteSql(args=(n_id, ), sql=Sql.deleteModel) self.Parent.Parent.Parent.updateTree() return
def count(ISSN): if "u_name" in session: if request.method == 'POST': COUNT = request.form['COUNT'] print(COUNT) """status = Sql.count(ISSN,COUNT)""" cart = Sql.add_cart(ISSN, COUNT, u_name=session['u_name']) """cart3=Sql.add_count(ISSN,u_name=session['u_name'])""" cart1 = Sql.add_cart1(ISSN).replace("\('", "").replace("\,')", "") print(cart1) return redirect(url_for('content', cnt=cart1)) return render_template("pub_form.html", val=session['u_name'], return_=status)
def isLinkedGroup(self, gid, *, cursor=None): if cursor is None: with Lib.Transaction.Transaction(self) as cursor: return Sql.first(cursor, Sql.IS_LINKED_GROUP, dict(gid=gid), default=False, Class=bool) else: return Sql.first(cursor, Sql.IS_LINKED_GROUP, dict(gid=gid), default=False, Class=bool)
def pay(): if "u_name" in session: """up_p=Sql.up_p(var,session['u_name'])""" cart3 = Sql.add_count(u_name=session['u_name']) cart4 = Sql.sum_total(u_name=session['u_name']) var1 = Sql.show_cart_data1(session['u_name']) """show=Sql.show_up_p(up_p,session['u_name'])""" var2 = Sql.show_cart_data2(session['u_name']) return render_template("payment.html", u_name=session['u_name'], VAL1=var1, VAL2=var2, cart=cart3, total=cart4)
def create_sample(self, event): """ 用户点击确定按钮后开始抽样并写入数据库 """ self.ssize = int(self.m_textCtrl_size.GetValue()) print self.param.para[0] self.stra = 0 # 具体策略编号 # FIXME: 这里由于元组的问题,必须传入足够多的参数,传入para的数量是现有分布所需参数个数的最大值 Sql.clear_sampling_result() # 先清空历史数据 # 进度条UI放入子线程: try: thread.start_new_thread(self.wait_writing, (len(self.param.para[0]), )) except: print "Error: unable to start thread"
def get_samp2(nid=9, arg_type=1): records = Sql.selectSql((nid, arg_type), Sql.get_samp2) flag = 0 for record in records: samps = record[1].decode('utf-8') samps = samps.split(',') print len(samps) samps = [float(samp) for samp in samps] if flag == 0: mat = samps flag = 1 else: mat = np.row_stack((mat, samps)) mat = np.mat(mat) print mat.shape mat = mat.T print mat.shape # mat = np.transpose(mat) # # mat = np.mat(mat) # print mat # print mat.shape # print type(mat) # print mat.shape # tmat = mat[:, 0:1] # print type(tmat) # print tmat.shape # shape = tmat.shape # print shape[0] return mat
def hasEntry(self, eid): with Lib.Transaction.Transaction(self) as cursor: return Sql.first(cursor, Sql.HAS_ENTRY, dict(eid=eid), default=False, Class=bool)
def run_real_model(inh_p, input_X): global cog_p_r args = Sql.selectSql(args=(cp.n_id,), sql=Sql.selectArgs_2) arg = [] for Xi in args: arg.append(Xi[0]) # real_cog_p_r = BuildMetaModel.real_cog_p_r # real_cog_p_r = real_cog_p_r.split(',') # cog_p_r = list() # for str1 in real_cog_p_r: # v1 = float(str1) # cog_p_r.append(v1) # print cog_p_r cog_p_r = arg cog_p_r = np.mat(cog_p_r) print cog_p_r order = ao.get_order(cp.n_id) shape_inh = inh_p.shape ret = RunImportedModel(order, cog_p_r, inh_p[0], input_X) for i in range(shape_inh[0]): if i==0: continue tret = RunImportedModel(order, cog_p_r, inh_p[i], input_X) ret = ret + tret ret = ret/shape_inh[0] return ret
def testSql(self): Sql.insert('test', 'test', 200) Sql.cursor.execute( '''select uname from test where uname like 'test' ''') Sql.cursor.commit user = Sql.cursor.fetchone() self.assertEqual(user.uname, 'test') Sql.cursor.execute('''select id from test where uname like 'test' ''') Sql.cursor.commit rid = Sql.cursor.fetchone() Sql.delete('test', rid.id) Sql.cursor.execute( '''select uname from test where uname like 'test' ''') Sql.cursor.commit testing = Sql.cursor.fetchone() self.assertIsNone(testing)
def __init__(self, parent, dbfile, cleanup=0): gridlib.Grid.__init__(self, parent, -1) if cleanup == 0: ds = Sql.DataStore(dbfile) cleanup = ds.GetLastCleanupRound() ds.Close() #print 'grid using cleanup #', cleanup table = CustomDataTable(cleanup, dbfile) # The second parameter means that the grid is to take ownership of the # table and will destroy it when done. Otherwise you would need to keep # a reference to it and call it's Destroy method later. self.SetTable(table, True) self.SetRowLabelSize(0) #hides row labels row #self.SetMargins(0,0) self.EnableEditing(False) self.EnableDragColMove(False) self.EnableDragColSize(False) self.EnableDragRowSize(False) self.EnableDragGridSize(False) self.FormatCells() self.AutoSizeColumns(True) self.AutoSizeRows(True) self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.onCellSelect)
def outputEntries(self, config): xrefSql = Sql.OUTPUT_XREFS.format(sortAs=config.SortAsRules) letter = None yield Output.Start(config.Title, config.Note) cursor = self.db.cursor() for record in cursor.execute(Sql.OUTPUT_ENTRIES): entry = Output.Entry(*record) if entry.indent == 0: char = _getChar(letter, entry) if char != letter: if not config.SectionTitles: yield Output.Section() else: if letter is None and char == SYMBOL: yield Output.Section(config.SectionSpecialTitle) else: yield Output.Section(char.upper()) letter = char subcursor = self.db.cursor() entry.childcount = Sql.first(subcursor, Sql.COUNT_SUBENTRIES, dict(peid=entry.eid), default=0) self._populateXRefs(subcursor, entry, xrefSql) yield entry yield Output.End()
def firstForPrefix(self, prefix): match = SANITIZE_MATCH_RX.search(prefix) if match is not None: prefix = prefix[:match.start()].rstrip() prefix = "^{}*".format(prefix.strip("^*")) with Lib.Transaction.Transaction(self) as cursor: return Sql.first(cursor, Sql.FIRST_FOR_PREFIX, dict(prefix=prefix))
def delete_sub(): if "u_name" in session: if request.method == 'POST': delete = Sql.delete_sub(u_name=session['u_name']) return render_template("payment.html", u_name=session['u_name']) return render_template("plan.html", u_name=session['u_name'])
def showingpublications(TYPE_): if "u_name" in session: data_ = Sql.fetch_data(session['u_name'], TYPE_) return render_template("pub_home.html", val=session['u_name'], data1=data_, img_path=os.path.join( app.config['UPLOAD_IMAGE'], session['u_name']).replace("\\", "/"))
def filteredCount(self, match, filter=FilterKind.TERMS_MATCHING): cursor = self.db.cursor() d = dict(match=match) if filter is FilterKind.PAGES_ORDER: sql = filter.sql_for_count(match) d = {} else: sql = getattr(Sql, "{}_COUNT".format(filter.name.upper())) return Sql.first(cursor, sql, d, default=0)
def content(cnt): if "u_name" in session: var = Sql.show_(cnt, session['u_name']) return render_template("show.html", val=var, u_name=session['u_name'], img_path=os.path.join( app.config['UPLOAD_IMAGE']).replace( "\\", "/"))
def pub_edit(): if "u_name" in session: data_ = Sql.fetch_data() return render_template("pub_form.html", val=session['u_name'], data1=data_, img_path=os.path.join( app.config['UPLOAD_IMAGE'], session['u_name']).replace("\\", "/"))
def validate(self): record = Sql.selectSql((self.account,), Sql.loginSql) if record == []: dlg = wx.MessageDialog(None, u"此用户不存在", u"登录失败", wx.OK | wx.ICON_EXCLAMATION) dlg.ShowModal() return False if record[0][1] != self.password: dlg = wx.MessageDialog(None, u"密码错误", u"登录失败", wx.OK | wx.ICON_EXCLAMATION) dlg.ShowModal() return False return True
def get_db_output(n): arr = Sqli.pull_last_n_entries(n) index = [] date = [] amount = [] index, date, amount = list(map(list, zip(*arr))) return date, amount
def login(uid, pwd): #验证登录 if uid == 'admin' and pwd == 'admin': session.set('admin', 2, '管理员', 'admin', '', '') return True data = Sql().get('user', whe={'uid': uid, 'pwd': pwd}) if data is None: return False else: session.set(data[2], data[4], data[1], data[0], data[10], data[11], [data[5], data[6]]) return True
def compileDiveFolders(self): #print 'compiling dive folders for kml' self.diveFolders = "" #clear existing ds = Sql.DataStore(self.DiveRTdbFile) for each in ds.GetKMLData(): folderBegin = self._diveFolders % each[0] self.diveFolders += folderBegin for ea in each[1]: placemark = self._divePlacemark % ea self.diveFolders += placemark self.diveFolders += "</Folder>\n" ds.Close()
def _filteredQuery(self, filter, match, offset, limit): # If there is a limit, and it includes the ROOT, we must add one # to the limit, since we skip the ROOT limit1 = limit + 1 if limit != UNLIMITED else limit sql, d = Util.sql_for_iterate(filter, match, offset, limit1) cursor = self.db.cursor() if filter is FilterKind.HAS_OVERLAPPING_PAGES: if not Sql.first(cursor, Sql.HAS_OVERLAPPING_PAGES_CACHE_COUNT, default=False, Class=bool): cursor.execute(Sql.HAS_OVERLAPPING_PAGES_CACHE_REFRESH) sql = Sql.HAS_OVERLAPPING_PAGES_CACHE_EIDS elif filter is FilterKind.SAME_TERM_TEXTS: if not Sql.first(cursor, Sql.SAME_TERM_TEXTS_CACHE_COUNT, default=False, Class=bool): cursor.execute(Sql.SAME_TERM_TEXTS_CACHE_REFRESH) sql = Sql.SAME_TERM_TEXTS_CACHE_EIDS return cursor, sql, d
def __init__(self, cleanupNumber, dbfile): gridlib.PyGridTableBase.__init__(self) self.DataStore = Sql.DataStore(dbfile) self.GetData(cleanupNumber) self.dataTypes = [ gridlib.GRID_VALUE_DATETIME, gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_STRING ] self.DataStore.Close()
def edit(ISSN): if "u_name" in session: if request.method == 'POST': image = request.files['pic'] Title = request.form['Title'] UNITS = int(request.form['unit']) TYPE_ = request.form['type'] DATE_ = request.form['date'] PRICE = int(request.form['Price']) IMAGE_name = secure_filename(image.filename) print("NOW SQL") Sql.edit_data(ISSN, Title, UNITS, PRICE, IMAGE_name, session['u_name']) print("SUCCss SQL") image.save( os.path.join(app.config['UPLOAD_IMAGE'], session['u_name'], secure_filename(image.filename))) status1 = Sql.edit_data1(TYPE_, ISSN, session['u_name']) return redirect('/pub_home') return render_template("edit.html", val=session['u_name'], isn=ISSN)