Пример #1
0
 def remove(self):
     problem_index = self.text_dialog.curselection();
     problem_id = self.text_dialog.get(problem_index);
     self.text_dialog.delete(self.text_dialog.curselection());
     DataCenter.PROBLEMLIST.remove(problem_id);
     DataCenter.save_problemlist();
     self.text_input.delete(0.0, tkinter.END);
Пример #2
0
 def run(self):
     while (1):
         if (DataCenter.POOL_SIZE_NOW < DataCenter.POOL_SIZE_LIMIT):
             DataCenter.POOL_SIZE_NOW += 1
             DataCenter.pdfdownload(self.url, self.path)
             if not os.exist("problemset"):
                 os.mkdir("problemset")
             shutil.move(self.path, "problemset/")
             DataCenter.POOL_SIZE_NOW -= 1
             break
         else:
             time.sleep(1)
Пример #3
0
    def removeData(self):
        """
        Method Name: removeData.

        Method use: Driver code to remove an Intern's Rating from the DataBase.
        """

        delList = []
        for item in self.RL.curselection():
            delList.append(self.RL.get(item))
            self.RL.delete(item)
        for item in delList:
            DataCenter.removeRating(item.split(' ')[0])
Пример #4
0
    def insert(self):
        self.token = ""
        instance = osquery.SpawnInstance()
        instance.open()
        while True:
            try:
                time.sleep(60)

                ret = instance.client.query(
                    "select command as cmd from crontab")
                res_s = ret.response

                joinstr = ""
                for item in res_s:
                    joinstr = joinstr + item['cmd']

                joinstr = joinstr + '192.168.1.5'
                import hashlib
                m1 = hashlib.md5()
                m1.update(joinstr)
                token = m1.hexdigest()

                import DataCenter
                log = DataCenter.Syslog("192.168.1.5")
                message_info = '{"source":"192.168.1.5","cnt":5,' + '"token":"' + token + '"}'
                log.send(message_info, syslog_client.Level.INFO)
                print(token)

            except KeyboardInterrupt:
                break
Пример #5
0
    def __init__(self, name="Bot", currency="BTC-USD", webSocket=None):

        #obtain credentials, authenticate GDAX client and websocket, and then over-write credentials
        self._passphrase = ""
        self._secret = ""
        self._key = ""
        self.get_credentials(credentials_file="../../credentials.txt"
                             )  #fills in passphrase, secret, and key

        #main body parts
        self._data_center = DataCenter(self)
        self._client = gdax.AuthenticatedClient(self._key, self._secret,
                                                self._passphrase)
        self._socket = webSocket
        self._trade_hands = TradeHands(self)

        #other bot stuff
        self._name = name
        self._currency = currency
        self._running = False
        self._fake_crypto = 0  #set an initial value for fake crypto
        self._fake_cash = 1000  #set an initial fake cash value

        self._socket.set_data_center(self._data_center)
        self._socket.set_bot(self)

        self.scramble_credentials()
Пример #6
0
    def finalizeRatings(self):
        """
            Method Name: finalizeRatings.

            Method Use: Format the rating data into desirable format and return back to the
                        Employee Window.
        """

        Rating_Str = ""
        for usr, rat in DataCenter.retrieveRating():
            Rating_Str += usr + " " + str(rat) + "\n"

        if not messagebox.askyesno(
                "Revive Data", "Should you want the rating data to be kept"):
            DataCenter.clearRatings()
        self.RW.destroy()
        self.employeeWindow(text=Rating_Str)
Пример #7
0
    def removeExistingIntern(self):
        """
        Method Name: removeExistingIntern

        Method use: To remove an Existing Intern from the DataBase
        """

        delList = []
        for i in self.IDLB.curselection():
            delList.append(self.IDLB.get(i))
        if messagebox.askyesno(
                "Are you sure to delete ? (This can't be undone)",
                "The following interns data is deleted:\n\n" +
                "\n".join(delList)):
            for item in delList:
                DataCenter.delete(item.split(' ')[2])
        self.RW.destroy()
        self.createRatings()
Пример #8
0
 def loadStats(self):
     #DataCenter.removeStats(self.pdata.pid)
     #return
     prev_data = DataCenter.readStats(self.pdata.pid)
     if not prev_data:
         data = TransactionManager.updateVotings(poll_addr=self.pdata.paddr)
         countings = dict(zip(self.pdata.popt, [0] * len(self.pdata.popt)))
         i = 0
         for option in data:
             if option in self.pdata.popt:
                 countings[option] += 1
             i += 1
         prev_data = str(countings) + "*" + str(i)
         print(prev_data)
         DataCenter.writeStats(self.pdata.pid, self.pdata.paddr, prev_data)
     else:
         ind = int(prev_data[0].split('*')[-1])
         data = TransactionManager.updateVotings(poll_addr=self.pdata.paddr,
                                                 ind=ind)
         #countings =  json.loads(prev_data[0].split('*')[0].replace("'","\""))
         countings = dict(zip(self.pdata.popt, [0] * len(self.pdata.popt)))
         i = 0
         for option in data:
             if option in self.pdata.popt:
                 countings[option] += 1
             i += 1
         prev_data = str(countings) + "*" + str(i)
         print(prev_data)
         DataCenter.updateStats(self.pdata.pid, prev_data)
     percentages = []
     total = sum(countings.values())
     if total == 0:
         for key in countings:
             self.garb = QtWidgets.QProgressBar()
             self.garb.setFormat(key + u' %p%')
             self.garb.setValue(0)
             self.PHolder.addWidget(self.garb)
     else:
         for key in countings:
             self.garb = QtWidgets.QProgressBar()
             self.garb.setFormat(key + u' %p%')
             self.garb.setValue((countings[key] / total) * 100)
             self.PHolder.addWidget(self.garb)
Пример #9
0
    def finalizePoll(self):
        question = self.InputQuestion.toPlainText()
        if len(question) <= 5:
            self.error_dialog = QtWidgets.QErrorMessage()
            self.dlg.status.setText(
                "Length Error: Length of Question can't be less than 5")
            return

        self.to_addr = TransactionManager.getPollAdress().decode().strip('\n')
        self.optionString = [
            question,
        ] + [
            str(self.OptionsArea.item(i).text())
            for i in range(self.OptionsArea.count())
        ] + [self.to_addr]

        print(self.optionString)
        choice = QtWidgets.QMessageBox.question(
            QtWidgets.QWidget(), "Confirm Transaction",
            "Do you want to post the poll to block chain ?",
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
        if choice == QtWidgets.QMessageBox.Yes:
            try:
                poll_id = TransactionManager.writeDatatoBlockchain(
                    '*'.join(self.optionString), self.to_addr, 0.3)
                #poll_id = "12345"
                print('*'.join(self.optionString))
                QtWidgets.QMessageBox(QtWidgets.QMessageBox.Information,
                                      "Transaction Success",
                                      "Poll posted to block chain!",
                                      QtWidgets.QMessageBox.Ok).exec_()
                QtWidgets.QMessageBox(
                    QtWidgets.QMessageBox.Information, "Poll id Information",
                    "Share this id with your audience so that they can vote!" +
                    "\nId: " + poll_id, QtWidgets.QMessageBox.Ok).exec_()
                DataCenter.write(poll_id, "*".join(self.optionString))
                print(DataCenter.readAll())
            except Exception as e:
                print(e)
                self.error_dialog = QtWidgets.QErrorMessage()
                self.error_dialog.setWindowTitle('Network Error')
                self.error_dialog.showMessage(
                    "Error in sending Poll! Please Try again")
Пример #10
0
 def loadData(self):
     data = DataCenter.readAll()
     self.dataList = []
     for row in data:
         # print(row)
         # pid = row[0]
         # pques = row[1].split('*')[0]
         # pdata = pques+' '*(80-len(pques))+pid
         pdata = PData(row)
         self.dataList.append(pdata)
         self.PollList.addItem(str(pdata))
Пример #11
0
    def CIB(self):
        """
        Method name: CIB.

        Method Use: Driver Code to add a new Intern to the DataBase.
        """
        if len(self.newNMEntry.get()) <= 3 or len(self.newUNMEntry.get()) <= 3:
            messagebox.showwarning(
                "Invalid Length",
                "The Intern Fields are either empty or under 3 charecters")
            return
        else:
            try:
                DataCenter.write(self.newNMEntry.get(), self.newUNMEntry.get())
            except:
                messagebox.showwarning("Invalid Data", "Please Check again")
                return
            messagebox.showinfo("Success", "New Intern Sucessfully added")
            self.NE.destroy()
            self.createRatings()
Пример #12
0
    def loadData(self, process=None):
        """
        Method name: loadData.

        Method use: GUI to take the Input from the user and load the data to the Rating Data Base.
        """

        self.ratList = []
        self.TMPEN = []
        if process:
            for name, rating in process:
                if float(rating.get()) >= 0 and float(rating.get()) <= 5:
                    DataCenter.insertRating(name, rating.get())
                else:
                    DataCenter.insertRating(name, -1)
            self.createRatings()
            return
        if not self.IDLB.curselection():
            messagebox.showinfo(
                "Empty Selection",
                "Please make sure to select at least one intern")
            return
        for i in self.IDLB.curselection():
            self.ratList.append(self.IDLB.get(i).split(' ')[2])
        self.RW.destroy()
        self.RAT = VerticalScrolledFrame(self.master)
        self.RAT.pack()
        self.LBL = Label(self.RAT.interior,
                         text="Enter a Rating for the selected interns: ")
        self.LBL.pack()
        for item, row in zip(self.ratList, range(1, len(self.ratList) + 1)):
            self.LBx = Label(self.RAT.interior, text=item)
            self.LBx.pack()
            self.TMPEN.append(Entry(self.RAT.interior))
            self.TMPEN[row - 1].pack()
        self.Sub = Button(
            self.RAT.interior,
            command=lambda: self.loadData(zip(self.ratList, self.TMPEN)),
            text="submit")
        self.Sub.pack(pady=8)
Пример #13
0
 def download(self, problem_id):
     try:
         
         problem_path = problem_id + ".pdf"
         problem_path = problem_path.strip();
         if(os.path.exists("problemset/" + problem_path)):
             return 1;
         if(problem_id[-1].isdigit()):
             problem_url = 'http://codeforces.com/problemset/problem/' + problem_id[:-2] + '/' + problem_id[-2:];
             if DataCenter.DEBUG:
                 print(problem_url);
         else:
             problem_url = 'http://codeforces.com/problemset/problem/' + problem_id[:-1] + '/' + problem_id[-1];
         problem_url = problem_url.strip();
         
         DataCenter.pdfdownload(problem_url , problem_path);
         
         shutil.move(problem_path, "problemset/")
         
     except Exception as e:
         return 0;
     return 0;
Пример #14
0
    def populateListBox(self):
        """
        Method Name: populateListBox

        Method use: To Format the rating Data and Fill it into the Intern's List
        """

        try:
            for data in enumerate(DataCenter.readAll(), 1):
                self.IDLB.insert(
                    END,
                    str(data[0]) + " " + str(data[1][0]) + " " +
                    str(data[1][1]))
        except:
            return
Пример #15
0
    def drag(self):
        lstr = r'''<a href="/problemset/problem/'''
        rstr = r'''</a>'''
#         pattern = re.compile(r'''()([.])*()''')
        dragnum = int(self.text_dragnum.get(0.0, tkinter.END));
        if DataCenter.DEBUG:
            print(dragnum);
        
        nowcnt = 0;
        pagenum = 0;
        while (nowcnt < dragnum):
            pagenum += 1;
            if(pagenum > DataCenter.CF_MAX_PROBLEMPAGE):
                break;
            result = DataCenter.OPENER.open("http://codeforces.com/problemset/page/" + str(pagenum) + "?order=BY_SOLVED_DESC");
            DataCenter.COOKIE.save(ignore_discard=True, ignore_expires=True)
            html_str = result.read().decode("utf-8");
            if DataCenter.DEBUG:
                DataCenter.output_to_file("test/problemset" + str(pagenum) + ".txt", html_str);
            DataCenter.CSRF_TOKEN = DataCenter.txt_wrap_by(r"<input type='hidden' name='csrf_token' value='", r"'/>", html_str);
            if DataCenter.DEBUG:
                print(DataCenter.CSRF_TOKEN);   
                
#             match = pattern.match(html_str)
#                 
#             if match:
#                 # 使用Match获得分组信息
#                 print(match.groups());
#                 nowcnt += match.groups().size();
            
            res = DataCenter.all_txt_wrap_by(lstr, rstr, html_str);
            for au in res:  
                tmps = "";
                i = 0;
                while(au[i] != "/"):
                    tmps += au[i];
                    i += 1;
                i += 1;
                tmps += au[i];
                au = tmps;
                if(au in DataCenter.BANLIST):
                    continue;
                if(au in DataCenter.PROBLEMLIST):
                    continue;
                else:
                    DataCenter.PROBLEMLIST.append(au);
                    self.text_dialog.insert(self.text_dialog.size(), au);
                    nowcnt += 1;
                if(nowcnt >= dragnum):
                    break;
        DataCenter.save_problemlist();
Пример #16
0
import os
import sys
import matplotlib.pyplot as plt

from GraphSLAM import GraphSLAM
import DataCenter

dirname = sys.argv[1]
method = int(sys.argv[2])

fname = os.path.join(dirname, "input.txt")
savefile = os.path.join(dirname, "result.png")

z, u, c, n = DataCenter.read(fname)

graphslam = GraphSLAM(z, u, c, n)

graphslam.main(method=method)
plt.savefig(savefile)
plt.show()
Пример #17
0
 def removeEntry(self):
     id = self.dataList[self.PollList.currentRow()].pid
     DataCenter.delete(id)
     item = self.PollList.takeItem(self.PollList.currentRow())
     item = None
Пример #18
0
 def clear(self):
     self.text_dialog.delete(0, self.text_dialog.size());
     DataCenter.PROBLEMLIST.clear();
     DataCenter.save_problemlist();
Пример #19
0
 def submit(self):
     problem_index = self.text_dialog.curselection();
     problem_id = self.text_dialog.get(problem_index);
     DataCenter.submit(problem_id);
Пример #20
0
 def ban(self):
     problem_index = self.text_dialog.curselection();
     problem_id = self.text_dialog.get(problem_index);
     DataCenter.BANLIST.append(problem_id);
     DataCenter.save_banlist();
     self.remove();
Пример #21
0
    def createRatings(self):
        """
            Method name: createRaNSEWtings.

            Method use: Provides a GUI for the Intern Rating.
        """
        try:
            self.EM.destroy()
        except:
            pass
        DataCenter.checkState()
        self.RW = Frame(self.master)
        self.RW.pack()
        self.IDLBL = Label(
            self.RW,
            text="Intern's Data\n(Sno  Intern Name  Intern User Name)")
        self.IDLBL.grid(row=0, column=1, padx=8, pady=8)
        self.RTLBL = Label(self.RW,
                           text="Rating Data\n( Intern User Name  Rating)")
        self.RTLBL.grid(row=0, column=4, padx=8, pady=8)
        self.IDLB = Listbox(self.RW, width=50, height=20, selectmode=MULTIPLE)
        self.scrollbar = Scrollbar(self.IDLB, orient=VERTICAL)
        self.IDLB.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.IDLB.yview)
        self.populateListBox()
        self.IDLB.grid(row=1, column=1, padx=16, pady=16, sticky=NSEW)
        self.loadImg = PhotoImage(file=self.resource_path("AddBtn.gif"))
        self.remImg = PhotoImage(file=self.resource_path("RenmBtn.gif"))
        self.removeIntern = Button(self.RW,
                                   height=48,
                                   width=48,
                                   image=self.remImg,
                                   command=self.removeData)
        self.removeIntern.grid(row=1, column=2, padx=8, pady=8)
        self.addIntern = Button(self.RW,
                                text="",
                                height=48,
                                width=48,
                                image=self.loadImg,
                                command=self.loadData)
        self.addIntern.grid(row=1, column=3, padx=8, pady=8)
        self.RL = Listbox(self.RW, width=50, height=20, selectmode=MULTIPLE)
        for usr, rat in DataCenter.retrieveRating():
            self.RL.insert(END, usr + " " + str(rat))
        try:
            self.RAT.destroy()
        except:
            pass
        self.RLscroll = Scrollbar(self.RL, orient=VERTICAL)
        self.RL.config(yscrollcommand=self.RLscroll.set)
        self.RLscroll.config(command=self.RL.yview)
        self.RL.grid(row=1, column=4, padx=16, pady=16)
        self.createIntern = Button(self.RW,
                                   text="Add a new Intern",
                                   command=self.newIntern)
        self.createIntern.grid(row=2, column=1, padx=8, pady=4)
        self.DeleteIntern = Button(self.RW,
                                   text="Remove an Existing Intern",
                                   command=self.removeExistingIntern)
        self.DeleteIntern.grid(row=3, column=1, padx=8, pady=4)
        self.finalBtn = Button(self.RW,
                               text="Finalize",
                               command=self.finalizeRatings)
        self.finalBtn.grid(row=3, column=4)
Пример #22
0
import DataCenter
import time
import Visuals
from pprint import pprint

_my_key = "<your_api_key_here>"


def check_hash(cs):
    iCon = NetWire.Connector(_my_key, cs)
    iCon.getConnection()
    return iCon.getInfo()


cs = FileProcessor.Loader(sys.argv[1]).compute()
D = DataCenter.Loader()
result = D.query(cs)
if result == None:
    result = check_hash(cs)
    if result['response_code'] != 1:
        print("Hash Not Found: Please Wait while we retrieve result")
        iUploader = NetWire.Uploader(_my_key,
                                     (sys.argv[1], open(sys.argv[1], 'rb')))
        iUploader.initUpload()
        time.sleep(30)
        t = 20
        result = check_hash(cs)
        while result['response_code'] != 1:
            print("Retrieving....")
            result = check_hash(cs)
            print(t)
Пример #23
0
def main():
    print("initializing dc...")
    dc = DataCenter()
    dc.initialize(ngrams_size=ngram_size)

    all_users_ngrams = dc.all_data['all_users_session_ngrams_processed']

    training_set = list()
    for user in all_users_ngrams:
        training_set.append(user[:50])

    # num_of_anns = len(all_users_ngrams)
    anns = list()

    if _train_anns:
        print("generating anns... ({})".format(num_of_anns))
        generate_anns(anns, dc)
        print("done.")
        print("training anns... ({})".format(num_of_anns))
        i = 0
        for user_ngrams, ann in zip(training_set, anns):
            train_ann(ann, i, training_set, user_ngrams,
                      not _prediction_classifiers_late_training, dc)
            if _save_anns:
                print("saving ann {}...".format(i + 1))
                save_model(ann, _model_save_path + str(i), overwrite=True)
            i += 1
    elif _load_anns:
        for i in range(num_of_anns):
            print("loading ann {}...".format(i + 1))
            anns.append(load_model(_model_save_path + str(i)))
    print("done.")

    if _evaluate:
        scores = list()
        print("for (i = {}; i < {}; i += {}) evaluate(i)".format(
            eval_epsilon, eval_epsilon + eval_step_size * num_of_eval_steps,
            eval_step_size))
        ep = eval_epsilon
        n = greatestn_n
        opt_ep, opt_n, max_score = ep, n, 0
        for i in range(num_of_eval_steps):
            current_score = evaluate_anns(anns, dc, ep, n)
            scores.append(current_score)
            if current_score > max_score:
                opt_ep = ep
                opt_n = n
                max_score = current_score
            ep += eval_step_size
            # n += 1
        print(",".join([str(s) for s in scores]))

    if _predict:
        print("predicting with ep={}, n={} (opt, score={}):".format(
            opt_ep, opt_n, max_score))
        predict_unknowns(anns, dc, training_set, opt_ep, opt_n)
        print("predicting with ep={}, n={} (score={}):".format(
            eval_epsilon, opt_n, scores[0]))
        predict_unknowns(anns, dc, training_set, opt_ep, opt_n)

    return
Пример #24
0
def dynamic(Account):
    '''
        动态,根据用户是否登入,来自动进入个人版。
    :param Account:
    :return:
    '''
    if session.get("account") != None:
        print("当前已经登入账号", session.get("account"))
    # 打开序列化过后的文件,进行反序列化处理
    fileRead = open('TempTxt/TemplateData.txt', 'rb')
    # 打开序列化过后的文件,进行反序列化处理
    golbalData = pickle.load(fileRead)
    # 获取 全局类 大字典文件。哔哩哔哩字典
    imgData = golbalData["BiliBili"]
    # # 将哔哩哔哩的内容随机取值
    # randomKey = random.choice(list(imgData.keys()))
    # # 将所有哔哩哔哩的内容取值
    # randomValue = imgData[randomKey]
    # ImgData = []
    # # 将按照对应关系进行处理
    # ImgData.append([randomKey,randomValue])
    # # 将SQLmanager的数据进行一下分类
    SqlManger_dynamic_Class = []
    all_Class_Set = set()
    # 循环全部SQLmanager列表获取数据
    for i in golbalData["SqlManger"]:
        all_Class_Set.add(i[2])
    # 开始动态判断
    if Account == "" or Account not in all_Class_Set:
        print("进入随机界面", Account)
        if Account == "biantai":
            Account = "H"
        elif Account == "heitai":
            Account = "HH"
        else:
            Account = "A"
        SqlManger_dynamic_Class = [
            i for i in golbalData["SqlManger"] if i[2] == Account
        ]
    #   当输入的参数不等于空且有值时且等于数据库的时
    elif Account != "" and Account in all_Class_Set:
        # 这里得做账号是否登入判断
        print("当前登入的账号是", session.get("account"))
        # 就算登入了但是想偷看其他人的资源库,也是禁止的,个人只能访问个人的资源库
        if session.get("account") != Account:
            return redirect("/")
        SqlManger_dynamic_Class = [
            i for i in golbalData["SqlManger"] if i[2] == Account
        ]
    # 尝试获取首页内容,如果不行,直接赋值为空
    try:
        fileRead_IndexContent = open('TempTxt/IndexContent.txt', 'rb')
        IndexContentDICT = pickle.load(fileRead_IndexContent)
        IndexContent = IndexContentDICT['IndexContent']
    except:
        IndexContent = "暂无公告喵喵喵~~~"
    # 处理掉 网站处于wait的网页
    tempLostList = []
    for k, v in golbalData["WebShell"].items():
        if v['status_code'] == "wating...":
            tempLostList.append(k)
    for num, li in enumerate(SqlManger_dynamic_Class):
        if li[1] in tempLostList:
            # 既然被删掉了,就得上报数据中心
            SqlManger_dynamic_Class.pop(num)
    # 既然被删掉了,就得上报数据中心
    DataCenterA = DataCenter.ReportingCenter(tempLostURL=tempLostList)
    # 处理掉 网站处于wait的网页
    return render_template('/index.html',
                           DataDict=golbalData["WebShell"],
                           DataList=SqlManger_dynamic_Class,
                           ImgData=imgData,
                           IndexContent=IndexContent)