Esempio n. 1
0
def Upload_house():
    if request.method == 'POST':
        ## step 1. load the file
        f = request.files['file']

        ## step 2. save the file
        f.save(secure_filename(f.filename))

        ## step 3. connect the service from ssh
        ### SSHConnection is the Class in ssh.py,its parameters contains(host=str, port=int, username=str,pwd=str)
        ssh_2 = SSHConnection(dic_s['host'], dic_s['port'], dic_s['username'],
                              dic_s['password'])
        ssh_2.connect()
        ssh_2.upload(
            str(os.getcwd()) + '/' + str(f.filename),
            dic_s['remote work directory path'] + '/lgbm/train1.csv')
        ## ssh_2.upload(LOCAL FILE PATH,REMOTE PATH)

        ##step 4. run data_v.py to get data of HousePrice
        global mydata  ## mydata is the visualization data of HousePrice data
        mydata = eval(ssh_2.cmd('cd lgbm;python data_v.py'))

        return render_template('Housedata_description.html', mydata=mydata)
    else:
        return render_template('Upload_house.html')
Esempio n. 2
0
def upload_s():
	if request.method == 'POST':

		f = request.files['file']
		f.save(secure_filename(f.filename))
		print(dic_s['password'])
		ssh_1=SSHConnection(dic_s['host'],dic_s['port'],dic_s['username'],dic_s['password'])
		ssh_1.connect()
		ssh_1.upload(str(os.getcwd()) + '\\' + str(f.filename),dic_s['remote work directory path'] + '/FlaskIndexPrediction/data/data.csv')  # INPUT YOUR PATH
		return render_template('index_s.html')

	else:
		return render_template('upload_s.html')
Esempio n. 3
0
def upload_h():
	if request.method == 'POST':

		f = request.files['file']
		f.save(secure_filename(f.filename))
		print(f.filename)
		global ssh
		ssh = SSHConnection(dic_s['host'],dic_s['port'],dic_s['username'],dic_s['password'])
		ssh.connect()
		ssh.upload(str(os.getcwd()) + '\\' + str(f.filename),dic_s['remote work directory path'] + '/lgbm/train1.csv')
		
		
		global mydata 
		mydata = eval(ssh.cmd('cd py2;source bin/activate;cd ..;cd lgbm;python data_v.py'))
		
		return render_template('index_h.html',mydata=mydata)
	else:
		return render_template('upload_h.html')
Esempio n. 4
0
def Upload_stock():
    if request.method == 'POST':
        ## step 1. load the file
        f = request.files['file']

        ## step 2. save the file
        f.save(secure_filename(f.filename))

        ## step 3. connect the service from ssh
        ### SSHConnection is the Class in ssh.py,its parameters contains(host=str, port=int, username=str,pwd=str)
        ssh_1 = SSHConnection(dic_s['host'], dic_s['port'], dic_s['username'],
                              dic_s['password'])
        ssh_1.connect()
        ssh_1.upload(
            str(os.getcwd()) + '/' + str(f.filename),
            dic_s['remote work directory path'] +
            '/FlaskIndexPrediction/data/data.csv')  # INPUT YOUR PATH
        ## ssh_1.upload(LOCAL FILE PATH,REMOTE PATH)
        return render_template('Choose_LSTM.html')

    else:
        return render_template('Upload_stock.html')
Esempio n. 5
0
def Housedata_parameter():
    def get(
        name
    ):  ##  get values from the HTML part ,'name' is the 'id' of HTML <input>
        return request.values.get(name)

    if request.method == 'POST':
        ##step 1. get housedata parameters from HTML
        LotArea = get("LotArea")
        Neighborhood = get("Neighborhood")
        YearBuilt = get("YearBuilt")
        GrLivArea = get("GrLivArea")
        Street = get("Street")
        Utilities = get("Utilities")
        LotConfig = get("LotConfig")
        HouseStyle = get("HouseStyle")
        RoofStyle = get("RoofStyle")
        SaleType = get('SaleType')
        SaleCondition = get('SaleCondition')
        lgbm_data = [
            LotArea, Street, Utilities, LotConfig, Neighborhood, HouseStyle,
            YearBuilt, RoofStyle, GrLivArea, SaleType, SaleCondition
        ]
        lgbm_data_1 = ",".join(lgbm_data)

        ##step 2. Data Processing.
        def getSortedValues(
            row
        ):  ## make data in a certain order('row' is the key for the data need to be sorted)
            sortedValues = []
            keys = row.keys()
            keys.sort()
            for key in keys:
                sortedValues.append(row[key])
            return sortedValues

        rows = [
            {
                'Column1': 1,
                'Column2': LotArea,
                'Column3': Street,
                'Column4': Utilities,
                'Column5': LotConfig,
                'Column6': Neighborhood,
                'Column7': HouseStyle,
                'Column8': YearBuilt,
                'Column9': RoofStyle,
                'Column10': GrLivArea,
                'Column11': SaleType,
                'Column12': SaleCondition
            },
        ]

        names = {
            'Column1': 'Id',
            'Column2': 'LotArea',
            'Column3': 'Street',
            'Column4': 'Utilities',
            'Column5': 'LotConfig',
            'Column6': 'Neighborhood',
            'Column7': 'HouseStyle',
            'Column8': 'YearBuilt',
            'Column9': 'RoofStyle',
            'Column10': 'GrLivArea',
            'Column11': 'SaleType',
            'Column12': 'SaleCondition'
        }

        ## step 3. write the sorted data in a csv file('test.csv')
        fileobj = open("module/YX/test.csv", 'wb')
        fileobj.write('\xEF\xBB\xBF')
        writer = csv.writer(fileobj)
        sortedValues = getSortedValues(names)
        writer.writerow(sortedValues)
        for row in rows:
            sortedValues = getSortedValues(row)
            print(sortedValues)
            writer.writerow(sortedValues)
        fileobj.close()

        ## step 4. upload test.csv
        ssh_3 = SSHConnection(dic_s['host'], dic_s['port'], dic_s['username'],
                              dic_s['password'])
        ssh_3.connect()
        ssh_3.upload(
            str(os.getcwd()) + '/module/YX/' + 'test.csv',
            '/root/lgbm/test.csv')

        ## step 5. running LGBM moudle to process the data
        show = ssh_3.cmd('cd lgbm;python lgbm.py')
        show_l = show.split('\n')  ## the output of lgbm.py in terminal
        # print "showl_l"
        # print show_l

        pred_y = eval(show_l[-2])  ##  the price output in list[]
        # print "pred_y"
        # print pred_y
        pred_y_show = pred_y[0]  ##  the price output in float
        # print "pred_y_show"
        # print pred_y_show
        quantitative = re.findall(
            "\d+", show_l[3])[0]  ## number of quantitative features
        qualitative = re.findall(
            "\d+", show_l[3])[1]  ## number of qualitative features
        train_x1 = show_l[6]  ## the shape of train_X(1018,11)
        # print "train_x1"
        # print  train_x1
        train_y1 = show_l[7]  ## the shape of train_y(1018,)
        # print "train_y1"
        # print  train_y1
        test_x1 = show_l[8]  ## the shape of test_x(1,11)
        # print "text_x1"
        # print  test_x1
        return render_template('House_final_output.html',
                               pred_y=round(pred_y_show, 2),
                               train_x1=train_x1,
                               train_y1=train_y1,
                               test_x1=test_x1,
                               quantitative=quantitative,
                               qualitative=qualitative)

    else:
        return render_template('Housedata_parameter.html', mydata=mydata)