Example #1
0
    def __init__(self):
        super().__init__()
        self.data_file = SaveData(SAVE_DATA_FILENAME)

        if os.path.isfile('datafile0.csv'):
            self.names = []
            f = open('datafile0.csv', encoding='utf-8')
            rdr = csv.reader(f)
            for line in rdr:
                self.names += [line[0]]
            f.close()

        self.UI()
Example #2
0
class Counter:
    def __init__(self):
        self.save_data = SaveData(env='dev')
        pass

    # 设置上游代理
    def request(self, flow: mitmproxy.http.HTTPFlow):
        if flow.request.method == "CONNECT":
            return

    def response(self, flow: mitmproxy.http.HTTPFlow):

        # 拦截包的信息
        if 'http://h5api.m.taobao.com/h5/mtop.mediaplatform.video.livedetail.itemlist' in flow.request.url:
            if len(flow.response.text) > 140:
                json_obj = json.loads(flow.request.query.get('data'))
                self.save_data.save_itemlist(flow.response.text, json_obj)

        # 淘宝主播直播场次接口
        if 'https://h5api.m.taobao.com/h5/mtop.taobao.maserati.xplan.render/' in flow.request.url:
            if len(flow.response.text) > 145:
                # anchorId = json.loads(flow.request.query.get('data')).get('accountId')
                self.save_data.save_feedsdetail(flow.response.text)

        if 'http://h5api.m.taobao.com/h5/mtop.mediaplatform.live.livedetail' in flow.request.url:
            if len(flow.response.text) > 140:
                liveId = json.loads(
                    flow.request.query.get('data')).get('liveId')
                self.save_data.save_livedetail(flow.response.text, liveId)

        # 淘宝直播接口
        if 'https://acs.m.taobao.com/gw/mtop.mediaplatform.live.searchv2' in flow.request.url:
            if len(flow.response.text) > 140:
                json_obj = json.loads(flow.response.text).get('data')
                self.save_data.save_anchor_info(json_obj)

        if 'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail' in flow.request.url:
            if len(flow.response.text) > 140:
                item_id = json.loads(flow.request.query.get('data')).get('id')
                self.save_data.item_info(item_id, flow.response.text)

        # 淘宝主播接口
        if 'https://acs.m.taobao.com/gw/mtop.mediaplatform.vtrade.searchcraftsmen' in flow.request.url:
            if len(flow.response.text) > 140:
                save_taobaoanchor_app_data(
                    json.loads(flow.response.text).get('data'))
Example #3
0
 def __init__(self):
     # sys.setdefaultencoding('utf-8')
     self.res_data = []  # 存放用户信息
     self.html_down = Html_Downloader()
     self.save_data = SaveData()
     self.entity = Entity()
     self.entity.rank = 0
     self.course_parser = Course_Parser()
     self.school = [0 for i in range(0, 88)]
     self.plat = [0 for i in range(0, 22)]
     self.lang = [0 for i in range(0, 3)]
     self.totalcourse = 0
     self.course_info = {}
     self.score = [0 for i in range(0, 11)]
     self.stud_test = [0 for i in range(0, 84)]
     self.cmt_score = [0 for i in range(0, 200)]
Example #4
0
 def __init__(self):
     super().__init__()
     self.data_file = SaveData(SAVE_DATA_FILENAME)
     self.UI()
Example #5
0
class Window(QMainWindow):
    isStart = False  #프로그램 Midi 로딩을 완료했는가?
    isPlaying = False  #음악이 실행되어 있는가?
    isWorking = True  #프로그램이 일하는 중인가?
    isControl = False  #사용자가 슬라이더를 컨트롤 중인가?

    a_point = None
    b_point = None

    def __init__(self):
        super().__init__()
        self.data_file = SaveData(SAVE_DATA_FILENAME)
        self.UI()

    def UI(self):
        self.resize(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setWindowTitle('MIDI Data Generator')
        self.setMaximumSize(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setMinimumSize(WINDOW_WIDTH, WINDOW_HEIGHT)

        self.cb_midi_list = QComboBox(self)
        self.cb_midi_list.move(650, 1)
        self.cb_midi_list.activated[str].connect(self.select)

        self.UI_Button()
        self.UI_Label()

        self.timeslider = QSlider(Qt.Horizontal, self)
        self.timeslider.move(30, 25)
        self.timeslider.setRange(0, 100)

        self.timeslider.resize(740, 50)
        self.timeslider.sliderPressed.connect(self.slider_control)
        self.timeslider.sliderReleased.connect(self.slider_release)

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_Space:
            self.music_play()

        if e.key() == Qt.Key_P:
            self.music_stop()

        if e.key() == Qt.Key_A:
            self.select_a()

        if e.key() == Qt.Key_B:
            self.select_b()

        if e.key() == Qt.Key_S:
            self.save()

        if e.key() == Qt.Key_C:
            self.clear()

        if e.key() == Qt.Key_Tab:
            self.next_midi()

        if e.key() == Qt.Key_1:
            self.play_a()

        if e.key() == Qt.Key_2:
            self.play_b()

        if e.key() == Qt.Key_Right:
            if self.isStart:
                self.audio.player.setPosition(
                    int(self.audio.player.position()) + 3000)

        if e.key() == Qt.Key_Left:
            if self.isStart:
                self.audio.player.setPosition(
                    int(self.audio.player.position()) - 3000)

    def UI_Button(self):
        bt_open = QPushButton('Open', self)
        bt_open.move(30, 0)
        bt_open.clicked.connect(self.open_file)

        bt_prev = QPushButton('Prev', self)
        bt_prev.resize(100, 70)
        bt_prev.move(30, 100)
        bt_prev.clicked.connect(self.prev_midi)

        bt_next = QPushButton('Next', self)
        bt_next.resize(100, 70)
        bt_next.move(130, 100)
        bt_next.clicked.connect(self.next_midi)

        bt_play = QPushButton('Play', self)
        bt_play.resize(70, 70)
        bt_play.move(250, 100)
        bt_play.clicked.connect(self.music_play)

        bt_stop = QPushButton('Stop', self)
        bt_stop.resize(70, 70)
        bt_stop.move(320, 100)
        bt_stop.clicked.connect(self.music_stop)

        bt_a = QPushButton('A', self)
        bt_a.resize(120, 70)
        bt_a.move(410, 100)
        bt_a.clicked.connect(self.select_a)

        bt_b = QPushButton('B', self)
        bt_b.resize(120, 70)
        bt_b.move(530, 100)
        bt_b.clicked.connect(self.select_b)

        bt_clear = QPushButton('Clear', self)
        bt_clear.resize(120, 70)
        bt_clear.move(650, 100)
        bt_clear.clicked.connect(self.clear)

        bt_play_a = QPushButton('Play A', self)
        bt_play_a.resize(190, 70)
        bt_play_a.move(30, 170)
        bt_play_a.clicked.connect(self.play_a)

        bt_play_b = QPushButton('Play B', self)
        bt_play_b.resize(190, 70)
        bt_play_b.move(215, 170)
        bt_play_b.clicked.connect(self.play_b)

        bt_clear_a = QPushButton('Clear A', self)
        bt_clear_a.resize(185, 70)
        bt_clear_a.move(400, 170)
        bt_clear_a.clicked.connect(self.clear_a)

        bt_clear_b = QPushButton('Clear B', self)
        bt_clear_b.resize(190, 70)
        bt_clear_b.move(580, 170)
        bt_clear_b.clicked.connect(self.clear_b)

        bt_save = QPushButton('Save', self)
        bt_save.resize(740, 60)
        bt_save.move(30, 300)
        bt_save.clicked.connect(self.save)

    def UI_Label(self):
        self.lb_status = QLabel('Status:Free', self)
        self.lb_status.move(160, 0)
        self.lb_status.resize(300, 30)

        self.lb_timer = QLabel('0.00', self)
        self.lb_timer.move(500, 0)

        self.lb_current_bpm = QLabel('Current BPM:', self)
        self.lb_current_bpm.move(30, 60)
        self.lb_current_bpm.resize(200, 30)

        self.lb_current_midi_index = QLabel('Index:    /', self)
        self.lb_current_midi_index.move(600, 60)
        self.lb_current_midi_index.resize(200, 30)

        self.lb_file_name = QLabel('File Name:', self)
        self.lb_file_name.move(30, 240)
        self.lb_file_name.resize(200, 30)

        self.lb_a_point = QLabel('A point:', self)
        self.lb_a_point.move(390, 240)
        self.lb_a_point.resize(200, 30)

        self.lb_b_point = QLabel('B point:', self)
        self.lb_b_point.move(590, 240)
        self.lb_b_point.resize(200, 30)

        self.lb_length = QLabel('Length:', self)
        self.lb_length.move(30, 270)
        self.lb_length.resize(200, 30)

        self.lb_bpm = QLabel('BPM:', self)
        self.lb_bpm.move(390, 270)
        self.lb_bpm.resize(200, 30)

        self.lb_total_data = QLabel(
            'Total Data: ' + str(self.data_file.total()), self)
        self.lb_total_data.move(30, 360)
        self.lb_total_data.resize(200, 30)

    def open_file(self):
        self.loc_folder = QFileDialog.getExistingDirectory(self)

        if self.loc_folder:
            self.isStart = True
            self.isWorking = True
            self.lb_status.setText("Status: Working")
            self.cb_midi_list.clear()
            self.cb_midi_list.clearFocus()

            files = [
                f for f in listdir(self.loc_folder)
                if isfile(join(self.loc_folder, f))
            ]

            self.midi_filename_list = [
                file for file in files
                if file.endswith('.mid') or file.endswith('.MID')
            ]
            self.midi_filename_list.sort()

            self.cb_midi_list.addItems(self.midi_filename_list)
            self.current_index = 0
            self.midi_total_index = len(self.midi_filename_list)

            self.lb_current_midi_index.setText('Index:    0/' +
                                               str(self.midi_total_index))

            th_load = Thread(target=self.load,
                             args=(self.midi_filename_list[0], ))
            th_load.start()

    def select(self, text):
        self.lb_status.setText("Status: Working")
        self.current_index = self.midi_filename_list.index(text)
        th_load = Thread(target=self.load, args=(text, ))
        th_load.start()

    def load(self, text):
        self.isWorking = True
        if self.isPlaying:
            self.audio.stop()
            self.isPlaying = False

        self.current_midi_name = text
        self.current_midi_file = music21.converter.parse(self.loc_folder +
                                                         '/' + text)
        self.current_midi_bpm = get_bpm(self.current_midi_file)

        self.lb_current_midi_index.setText('Index:    ' +
                                           str(self.current_index + 1) + '/' +
                                           str(self.midi_total_index))
        self.lb_current_bpm.setText('Current BPM: ' +
                                    str(self.current_midi_bpm))
        self.lb_bpm.setText('BPM: ' + str(self.current_midi_bpm))
        self.lb_file_name.setText('Filename: ' + self.current_midi_name)

        if self.current_midi_bpm != None:
            QApplication.processEvents()
            midi_to_audio(self.loc_folder + '/' + self.current_midi_name,
                          'tmp.wav')
            self.audio = Player('tmp.wav')
            self.lb_length.setText('length: ' + str(int(self.audio.length)) +
                                   ' s')
            self.clear()
            self.lb_status.setText('Status: Free')
        else:
            self.lb_status.setText('Status: Can\'t read BPM!')

        self.isWorking = False

    def next_midi(self):
        if self.isStart:
            QApplication.processEvents()
            if self.current_index < self.midi_total_index:
                self.lb_status.setText("Status: Working")
                self.current_index += 1
                self.cb_midi_list.setCurrentIndex(self.current_index)
                th_load = Thread(
                    target=self.load,
                    args=(self.midi_filename_list[self.current_index], ))
                th_load.start()
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def prev_midi(self):
        if self.isStart:
            QApplication.processEvents()
            if self.current_index > 0:
                self.lb_status.setText("Status: Working")
                self.current_index -= 1
                self.cb_midi_list.setCurrentIndex(self.current_index)
                th_load = Thread(
                    target=self.load,
                    args=(self.midi_filename_list[self.current_index], ))
                th_load.start()
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def music_play(self):
        if self.isStart:
            if self.isWorking == False:
                if self.isPlaying:
                    self.audio.pause()
                    self.isPlaying = False
                else:
                    self.isPlaying = True
                    th_updater = Thread(target=self.audio_ui_update)
                    th_updater.start()

                    try:
                        self.audio.play()
                    except:
                        self.isPlaying = False
                        QMessageBox.about(self, 'Error', 'Can\'t read BPM!')
            else:
                QMessageBox.about(self, "Error", "Process is working...")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def music_stop(self):
        if self.isStart:
            if self.isWorking == False:
                if self.isPlaying:
                    self.audio.stop()
                    self.timeslider.setValue(0)
                    self.lb_timer.setText('0.00')
                    self.isPlaying = False
            else:
                QMessageBox.about(self, "Error", "Process is working...")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def audio_ui_update(self):
        QApplication.processEvents()
        while self.isPlaying:
            self.lb_timer.setText('%.2f' %
                                  (self.audio.player.position() * 0.001))

            if self.isControl == False and self.isPlaying == True:
                self.timeslider.setValue(self.audio.player.position() * 0.001 /
                                         int(self.audio.length) * 100)

    def slider_control(self):
        self.isControl = True

    def slider_release(self):
        if self.isStart:
            self.audio.player.setPosition(
                int(self.timeslider.value() * 10 * self.audio.length))
        self.isControl = False

    def select_a(self):
        QApplication.processEvents()
        if self.isStart:
            if self.isWorking == False:
                self.a_point = round(self.audio.player.position() * 0.001, 2)
                self.lb_a_point.setText('A point: ' + str(self.a_point))
            else:
                QMessageBox.about(self, "Error", "Process is working...")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def select_b(self):
        QApplication.processEvents()
        if self.isStart:
            if self.isWorking == False:
                self.b_point = round(self.audio.player.position() * 0.001, 2)
                self.lb_b_point.setText('B point: ' + str(self.b_point))
            else:
                QMessageBox.about(self, "Error", "Process is working...")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def play_a(self):
        QApplication.processEvents()
        if self.isStart:
            if self.b_point != None:
                self.audio.player.setPosition(self.a_point * 1000)
                if self.isPlaying == False:
                    self.music_play()
            else:
                QMessageBox.about(self, "Error", "Please set the point.")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def play_b(self):
        QApplication.processEvents()
        if self.isStart:
            if self.b_point != None:
                self.audio.player.setPosition(self.b_point * 1000)
                if self.isPlaying == False:
                    self.music_play()
            else:
                QMessageBox.about(self, "Error", "Please set the point.")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")

    def clear(self):
        QApplication.processEvents()
        self.a_point = None
        self.b_point = None
        self.lb_a_point.setText('A point: ')
        self.lb_b_point.setText('B point: ')
        self.timeslider.setValue(0)
        self.lb_timer.setText('0.00')

    def clear_a(self):
        QApplication.processEvents()
        self.a_point = None
        self.lb_a_point.setText('A point: ')

    def clear_b(self):
        QApplication.processEvents()
        self.b_point = None
        self.lb_b_point.setText('B point: ')

    def save(self):
        if self.isStart:
            if self.isWorking == False:
                if self.current_midi_name and self.audio.length and self.current_midi_bpm and self.a_point and self.b_point:
                    QApplication.processEvents()
                    self.data_file.write_data([
                        self.loc_folder + self.current_midi_name,
                        int(self.audio.length), self.current_midi_bpm,
                        self.a_point, self.b_point
                    ])
                    self.lb_total_data.setText('Total Data: ' +
                                               str(self.data_file.total()))
                    QMessageBox.about(self, "Complete", "Save complete!")
                else:
                    QMessageBox.about(self, "Error", "Please enter the data.")
            else:
                QMessageBox.about(self, "Error", "Process is working...")
        else:
            QMessageBox.about(self, "Error", "Please load MIDI file.")
Example #6
0
from sklearn.cross_validation import train_test_split
from sklearn.cross_validation import cross_val_score
from sklearn import linear_model

import os
import sys

import time
from datetime import datetime, date, time, timedelta

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()

accuracy = {}
meanSquaredError = {}

symbols = getData.getAllSymbols()

reg = linear_model.Lasso(alpha=0.1,
                         fit_intercept=False,
                         normalize=True,
                         precompute=True,
                         copy_X=False,
                         max_iter=10000000,
                         tol=0.000001,
                         warm_start=True,
                         positive=False,
Example #7
0
from sklearn.linear_model import SGDClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

import os
import sys

import time
from datetime import datetime, date, time, timedelta

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()

symbols = getData.getAllSymbols()

for symbol in symbols:     
    # we just predict up/down of close price #
    result = getData.getSymbolCLFLabels(symbol, 4)
    features = getData.getSymbolFeaturesWithoutDate(symbol)
    allFeatures = getData.getSymbolFeatures(symbol)
    dates = []

    for feature in allFeatures:
        dates.append(feature[0])

    # create train and test data set #
    high = len(features)
Example #8
0
    def get_coursedetail(self, course_as, cmt_score, stu_rank):
        self.school = [0 for i in range(0, 88)]
        self.plat = [0 for i in range(0, 22)]
        self.lang = [0 for i in range(0, 3)]
        self.sourse_disp = 0
        self.plat_disp = 0
        self.save_data = SaveData()
        self.course_info = {}
        self.score = [0 for i in range(0, 11)]
        self.stud_test = [0 for i in range(0, 84)]
        self.course_odd_num = 0
        self.course_index = -1
        self.course_info1 = {}

        for course_a in course_as:
            print "enter again"
            flag = 0
            self.course_index = self.course_index + 1
            course_href = course_a['href']
            print "1"
            try:
                self.course_info["img_href"] = "None"
                course_detail = self.html_down.download(course_href)
                #Beautiful Soup×Ô¶¯½«ÊäÈëÎĵµ×ª»»ÎªUnicode±àÂ룬Êä³öÎĵµ×ª»»Îªutf-8±àÂë¡£
                soup_course = BeautifulSoup(course_detail, 'html.parser')

                print "2"
                #try:
                print "course_href", course_href
                self.course_info["course_id"] = course_href.split('/')[4]
                if (int(self.course_info["course_id"]) % 2) == 1:
                    print "before flag = ", flag
                    print self.course_info["course_id"]
                    flag = 1
                    print "after flag = ", flag
                else:
                    self.course_odd_num = self.course_odd_num + 1
                    self.stud_test[
                        self.course_odd_num] = self.course_info["course_id"]

                print "3"
                self.course_info["imgid"] = str(
                    self.course_info["course_id"]) + ".jpg"
                self.course_info["course_name"] = soup_course.find(
                    'title').text.strip().split(' ')[0]
                #self.course_info["course_name"] = course_href.split('/')[5]
                print "\n"
                print self.course_info["course_name"]
                self.course_info["course_href"] = course_href

                print "4"
                plat_regexp = re.compile("/platform/*")
                plat_info = soup_course.find('a', href=plat_regexp)
                school_regexp = re.compile("school_id")
                school_info = soup_course.find('a', href=school_regexp)
                try:
                    # print plat_info.text.replace(' ','').replace('\n','').encode('gbk')
                    ind1 = int(PLAT_DICT[plat_info.text.replace(
                        ' ', '').replace('\n', '').encode('gbk')])
                    self.course_info["course_plat"] = plat_info.text.replace(
                        ' ', '').replace('\n', '')
                    #print "course_plat == ",self.course_info["course_plat"]
                    if flag == 1:
                        self.plat[ind1] = self.plat[ind1] + 1
                        self.plat_disp = self.plat_disp + 1
                        self.course_info["cour_plat_id"] = ind1 + 1
                except:
                    test_exist = plat_info.text.replace('\n', '').encode('gbk')
                    ind1 = int(PLAT_DICT['others'])
                    self.course_info["course_plat"] = "others"
                    if flag == 1:
                        self.plat[ind1] = self.plat[ind1] + 1
                        self.course_info["cour_plat_id"] = 0

    #                    print "other plats"
    #                    print plat_info.text.replace('\n','').encode('gbk')
                try:
                    print school_info.text.replace('\n', '').encode('gbk')
                    ind2 = int(COURSE_DICT[school_info.text.replace(
                        '\n', '').encode('gbk')])

                    self.course_info[
                        "course_school"] = school_info.text.replace('\n', '')
                    #print "course_school = ",self.course_info["course_school"]
                    if flag == 1:
                        self.school[ind2] = self.school[ind2] + 1
                        self.course_info["cour_school_id"] = ind2 + 1
                        self.sourse_disp = self.sourse_disp + 1
                except:
                    #ÈôÒ³Ãæ´æÔÚ
                    test_exist = school_info.text.replace('\n',
                                                          '').encode('gbk')
                    ind2 = int(COURSE_DICT['others'])
                    self.course_info["course_school"] = "others"
                    if flag == 1:
                        self.school[ind2] = self.school[ind2] + 1
                        self.course_info["cour_school_id"] = 0
                    #print "other schools"
                    #print "               "+school_info.text.replace('\n','').encode('gbk')
                try:
                    course_langinfo = soup_course.find('ul',
                                                       class_="course-info")
                    if "ÖÐÎÄÊÚ¿Î" in str(course_langinfo.encode('gbk')):
                        if flag == 1:
                            self.lang[0] = self.lang[0] + 1
                        self.course_info["course_lang"] = "ÖÐÎÄÊÚ¿Î".decode(
                            'gbk')
                        self.course_info["cour_lang_id"] = 1
                    elif "Ó¢ÓïÊÚ¿Î" in str(course_langinfo.encode('gbk')):
                        if flag == 1:
                            self.lang[1] = self.lang[1] + 1
                        self.course_info["course_lang"] = "Ó¢ÎÄÊÚ¿Î".decode(
                            'gbk')
                        self.course_info["cour_lang_id"] = 2
                    else:
                        #ÈôÒ³Ãæ´æÔÚ
                        test_exist = school_info.text.replace('\n', '')
                        if flag == 1:
                            self.lang[2] = self.lang[2] + 1
                    print "course_lang = ", self.course_info["course_lang"]
                except:
                    print "lang wrong"

                print "5"

                try:
                    #±£´æÆÀ·Ö5-9
                    course_score = soup_course.find(
                        'span', class_="course-score-average")
                    self.course_info["course_score"] = course_score.text
                    if "ÔÝÎÞÆÀ¼Û".decode(
                            'gbk') in self.course_info["course_score"].replace(
                                '\n', '').replace(' ', ''):
                        print "ÔÝÎÞÆÀ¼Û"
                        self.course_info["course_score"] = "None"
                        self.course_info["cour_score_id"] = 0
                        if flag == 1:
                            self.score[0] = self.score[0] + 1

                    print "course_score = ", float(
                        self.course_info["course_score"])
                    if self.course_info["course_score"] == "None":
                        print self.course_info["course_score"]
                        if flag == 1:
                            self.score[0] = self.score[0] + 1  #others
                        self.course_info["cour_score_id"] = 0
                    elif float(self.course_info["course_score"]) >= 9.0:
                        print "9"
                        if flag == 1:
                            self.score[9] = self.score[9] + 1
                        self.course_info["cour_score_id"] = 9
                    elif float(self.course_info["course_score"]) >= 8:
                        print "8"
                        if flag == 1:
                            self.score[8] = self.score[8] + 1
                        self.course_info["cour_score_id"] = 8
                    elif float(self.course_info["course_score"]) >= 7:
                        print "7"
                        if flag == 1:
                            self.score[7] = self.score[7] + 1
                        self.course_info["cour_score_id"] = 7
                    elif float(self.course_info["course_score"]) >= 6:
                        print "6"
                        if flag == 1:
                            self.score[6] = self.score[6] + 1
                        self.course_info["cour_score_id"] = 6
                    elif float(self.course_info["course_score"]) >= 5:
                        print "5"
                        if flag == 1:
                            self.score[5] = self.score[5] + 1
                        self.course_info["cour_score_id"] = 5
                except:
                    print "score wrong"
                try:
                    course_duration = soup_course.find(
                        'p', class_="course-duration")
                    self.course_info["course_duraweek"] = course_duration.find(
                        'b').text.split('/')[0]
                    self.course_info["course_durahour"] = course_duration.find(
                        'b').text.split('/')[1]
                except:
                    self.course_info["course_durahour"] = "None"
                    self.course_info["course_duraweek"] = "None"
                    print "duration wrong"
                try:
                    course_go = soup_course.find('a', class_="course-go")
                    self.course_info["course_go"] = course_go["href"]
                    print self.course_info["course_go"]
                except:
                    print "course_go wrong"
                try:
                    course_start = soup_course.find('p', class_="course-start")
                    self.course_info[
                        "course_start"] = course_start.text.encode(
                            'gbk').split('£º')[1].decode('gbk')
                    print self.course_info["course_start"]
                except:
                    print "course_info wrong"
                print "enter savecourse-info"
                self.course_info1["course_id"] = self.course_info["course_id"]
                self.course_info1["cour_school_id"] = self.course_info[
                    "cour_school_id"]
                self.course_info1["cour_score_id"] = self.course_info[
                    "cour_score_id"]
                self.course_info1["cour_lang_id"] = self.course_info[
                    "cour_lang_id"]
                self.course_info1["cour_plat_id"] = self.course_info[
                    "cour_plat_id"]
                print "selfcourse_id", self.course_info["course_id"]
                #½«ÐÅÏ¢²åÈëÊý¾Ý¿â
                self.save_data.ins_course_in(self.course_info1)

                print "score", cmt_score[self.course_index]
                print "stu_rank", stu_rank
                self.save_data.ins_cmt_score(self.course_info["course_id"],
                                             cmt_score[self.course_index],
                                             stu_rank)
                # self.save_data.ins_cs(self.course_index,self.course_info["course_id"],stu_rank)
            except:
                continue

        return self.school, self.plat, self.lang, self.score, self.stud_test
Example #9
0
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.data_file = SaveData(SAVE_DATA_FILENAME)

        if os.path.isfile('datafile0.csv'):
            self.names = []
            f = open('datafile0.csv', encoding='utf-8')
            rdr = csv.reader(f)
            for line in rdr:
                self.names += [line[0]]
            f.close()

        self.UI()

    def UI(self):
        self.resize(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setWindowTitle('Manual MIDI Data Generator')
        self.setMaximumSize(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setMinimumSize(WINDOW_WIDTH, WINDOW_HEIGHT)

        self.lb_filename = QLabel('Filename', self)
        self.lb_filename.move(10, 0)
        self.lb_filename.resize(300, 30)

        self.te_filename = QTextEdit(self)
        self.te_filename.move(10, 30)
        self.te_filename.resize(380, 30)

        self.lb_length = QLabel('Length', self)
        self.lb_length.move(10, 60)
        self.lb_length.resize(300, 30)

        self.te_length = QTextEdit(self)
        self.te_length.move(10, 90)
        self.te_length.resize(380, 30)

        self.lb_bpm = QLabel('BPM', self)
        self.lb_bpm.move(10, 120)
        self.lb_bpm.resize(300, 30)

        self.te_bpm = QTextEdit(self)
        self.te_bpm.move(10, 150)
        self.te_bpm.resize(380, 30)

        self.lb_a_point = QLabel('A Point', self)
        self.lb_a_point.move(10, 180)
        self.lb_a_point.resize(300, 30)

        self.te_a_point = QTextEdit(self)
        self.te_a_point.move(10, 210)
        self.te_a_point.resize(380, 30)

        self.lb_b_point = QLabel('B Point', self)
        self.lb_b_point.move(10, 240)
        self.lb_b_point.resize(300, 30)

        self.te_b_point = QTextEdit(self)
        self.te_b_point.move(10, 270)
        self.te_b_point.resize(380, 30)

        self.bt_save = QPushButton(self)
        self.bt_save.setText('Save')
        self.bt_save.move(5, 310)
        self.bt_save.resize(390, 50)
        self.bt_save.clicked.connect(self.save)

        self.lb_count = QLabel(
            'Number of Data : ' + str(self.data_file.total()), self)
        self.lb_count.move(10, 360)
        self.lb_count.resize(300, 30)

        self.bt_clear = QPushButton(self)
        self.bt_clear.move(190, 360)
        self.bt_clear.resize(200, 30)
        self.bt_clear.setText('Clear')
        self.bt_clear.clicked.connect(self.clear)

    def save(self):
        if self.te_filename.toPlainText() and self.te_a_point.toPlainText(
        ) and self.te_b_point.toPlainText() and self.te_bpm.toPlainText(
        ) and self.te_length:
            if self.te_filename.toPlainText(
            ) + '.mid' in self.names or self.te_filename.toPlainText(
            ) + '.MID' in self.names:
                QMessageBox(self, 'Error', 'Data exists!')
            else:
                self.names += [self.te_filename.toPlainText()]
                self.data_file.write_data([
                    self.te_filename.toPlainText(),
                    self.te_length.toPlainText(),
                    self.te_bpm.toPlainText(),
                    self.te_a_point.toPlainText(),
                    self.te_b_point.toPlainText()
                ])
                self.lb_count.setText('Number of Data : ' +
                                      str(self.data_file.total()))
                self.clear()
            QMessageBox.about(self, 'Save', 'Complete!')
        else:
            QMessageBox.about(self, 'Alert', 'Type all data!')

    def clear(self):
        QApplication.processEvents()
        self.te_a_point.setPlainText('')
        self.te_b_point.setPlainText('')
        self.te_bpm.setPlainText('')
        self.te_length.setPlainText('')
        self.te_filename.setPlainText('')
Example #10
0
import os
import sys

# get_data_block_start
from get_data import GetData
from save_data import SaveData
from get_prediction_data import GetPredictionData
from priorityQueueImpl import PriorityQueueImpl
from save_top_5_and_last_5 import SaveRank

getData = GetData()
saveData = SaveData()
getPredictionData = GetPredictionData()
saveRank = SaveRank()

symbols = getData.getAllSymbols()

map = {
    'date': 0,
    'open': 1,
    'high': 2,
    'low': 3,
    'close': 4,
    'adjClose': 5,
    'volume': 6
}
prediction_map = {
    'Date': 0,
    'DTree': 1,
    'SVM': 2,
    'SGDLinear': 3,
Example #11
0
 def save(self, data):
     """保存数据到数据库中"""
     save_data = SaveData(data)
     save_data.save()
from sklearn.cross_validation import cross_val_score
from sklearn.linear_model import SGDRegressor

import os
import sys
import numpy as np

# save accuracy score
results = open(os.path.basename(__file__)+'.csv', 'w')

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()

accuracy = {}
meanSquaredError = {}

symbols = getData.getAllSymbols()

# Situation 2: Use yesterday's 'open' 'low' 'hign' price to predict current day's 'close' price #
# Result: Still high accracy, some stocks are extremly unaccurare

for symbol in symbols:

    # data column: Date|Open|High|Low|Close|Adj_Close
    allFeatures = getData.getSymbolFeatures(symbol)

    accuracy[symbol] = []
from sklearn import tree
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

import os
import sys

import time
from datetime import datetime, date, time, timedelta

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()


symbols = getData.getAllSymbols()
# get_data_block_end

for symbol in symbols:     
    # we just predict up/down of close price #
    result = getData.getSymbolCLFLabels(symbol, 4)
    features = getData.getSymbolFeatures(symbol)
    dates = []

    for feature in features:
        dates.append(feature[0])

    # create train and test data set #
Example #14
0
# Data Entry Automation - Rental finder

from find_rentals import FindRentals
from save_data import SaveData

find_rentals = FindRentals()

find_rentals.find_rentals()

prices = find_rentals.price
addresses = find_rentals.address
links = find_rentals.links

save_data = SaveData(prices, addresses, links)
Example #15
0
 def __init__(self):
     self.save_data = SaveData(env='dev')
     pass
Example #16
0
from sklearn.linear_model import SGDRegressor

import os
import sys
import numpy as np

import time
from datetime import datetime, date, time, timedelta

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()

symbols = getData.getAllSymbols()

reg = SGDRegressor(max_iter=1e6,
                   loss='huber',
                   penalty='l2',
                   fit_intercept=False,
                   shuffle=False,
                   tol=1e-4,
                   eta0=1e-4,
                   average=True,
                   warm_start=True)

# Situation 2: Use yesterday's 'open' 'low' 'hign' price to predict current day's 'close' price #
# Result: Still high accracy, some stocks are extremly unaccurare
Example #17
0
from sklearn.linear_model import SGDClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

import os
import sys

# get_data_block_start
from get_data import GetData
from save_data import SaveData

getData = GetData()
saveData = SaveData()

accuracy = {}

symbols = getData.getAllSymbols()

for symbol in symbols:
    accuracy[symbol] = []
     
    # we just predict up/down of close price #
    result = getData.getSymbolCLFLabels(symbol, 4)
    features = getData.getSymbolFeaturesWithoutDate(symbol)
    allFeatures = getData.getSymbolFeatures(symbol)
    dates = []

    for feature in allFeatures:
        dates.append(feature[0])

    # create train and test data set #