Beispiel #1
0
def audioAnalysis(time, path):
    ans = receive2.data_request(duration=time, path=path)

    if ans == True:
        name1 = 'tempdata'

        file1 = open(path + name1 + '.txt', 'r')
        comb1 = parseData.parse(file1, 'comb')

        mean_magnitude1 = parseData.calc_mean_magnitude(comb1, 128, path)
        max_val1 = parseData.calc_max_val(comb1, 128, path)
        min_val1 = parseData.calc_min_val(comb1, 128, path)
Beispiel #2
0
def detect(curr):
    if True:
        #time.time() - curr > secondInterval:
        snapshot.snapshot()
        results = parseData.parse("snapshot.jpg")
        reservationLicense = ""
        #print "Requesting plate from parent"
        socket.send("1".encode("utf8"))
        #print "Waiting for response"
        reservationLicense = socket.recv().decode("utf8")
        #print "Received response from parent: " + reservationLicense
        if len(results) > 0:
            print "Detected vehicle, seeing if it matches a reservation"
            for result in results:
                print "Comparing " + result + " with " + reservationLicense
                if result == reservationLicense:
                    print "Found match"
                    socket.send(result.encode("utf8"))
                    try:
                        response = socket.recv().decode("utf8")
                    except:
                        sys.exit()
                    #sys.stdout.flush()
                    return result
            print "No match found"
            socket.send("NA".encode("utf8"))
            try:
                response = socket.recv().decode("utf8")
            except:
                sys.exit()

            #sys.stdout.flush()
        else:
            print "No detections"
            #print("No vehicle detected")
            socket.send("NA".encode("utf8"))
            try:
                response = socket.recv().decode("utf8")
            except:
                sys.exit()
            #sys.stdout.flush()
    return "NA"
import parseData
import analysis

path = r"C:\Users\Yijun\Desktop\Amazon\reviews_Clothing,_Shoes_&_Jewelry.txt"
pathProduct = r"C:\Users\Yijun\Desktop\Amazon\meta_Clothing,_Shoes_&_Jewelry.txt"
outfile = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_unique.txt"
outfile2 = r"C:\Users\Yijun\Desktop\Amazon\reviews_shoes.txt"
outfile3 = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_hasReview.txt"
outfile4 = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_unique+review+price.txt"
outfile5 = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_unique+fifteen_review+price.txt"


# separate shoes datac
parseData.parseAndWrite(pathProduct, outfile, "Shoes")
shoes = parseData.parse(outfile)

# extract shoe reviews
productIDs = set()
for item in shoes:
  if item.has_key('asin'):
    productIDs.add(item['asin'])

parseData.parseAndWrite_constraint(path, outfile2, productIDs)

# extract shoe product data that has review
reviews = parseData.parse(outfile2)

len(reviews)	# 1521651

unique = set()
for i in reviews:
import numpy
import scipy.optimize

import parseData
import analysis

pathProducts = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_unique+fifteen_review+price.txt"
pathReviews = r"C:\Users\Yijun\Desktop\Amazon\reviews_shoes_unique+fifteen_review+price.txt"
pathLabels = r"C:\Users\Yijun\Desktop\Amazon\labels.txt"

shoes = parseData.parse(pathProducts)
reviews = parseData.parse(pathReviews)
labels = parseData.loadLabels(pathLabels)

sample_shoes = dict()
for i in shoes:
  if i['asin'] in labels.keys():
    sample_shoes[i['asin']] = i

sample_reviews = list()
for i in reviews:
  if i['asin'] in labels.keys():
    sample_reviews.append(i)

def feature(key):
  feat = [1]
  feat.append(sample_shoes[key]['price'])  # price feature
  count = 0
  for i in sample_reviews:
    if i['asin'] == key:
      count += 1
import random

import parseData
import analysis

outfile = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_unique.txt"

# parse shoes data
shoes = parseData.parse(outfile)

len(shoes) # 366654

# randomly choose 100 data
sample = random.sample(shoes, 100)

for i in range(0,100):
  print sample[i]['asin']

for i in range(0,100):
  print sample[i]['title']

for i in range(0,100):
  print sample[i]['imUrl']

for i in range(0,100):
  if sample[i].has_key('price'):
    print sample[i]['price']
  else:
    print

sample
Beispiel #6
0
import parseData
import analysis

import numpy
import matplotlib.pyplot
from scipy.stats import gaussian_kde

import operator

outfile2 = r"C:\Users\Yijun\Desktop\Amazon\reviews_shoes.txt"
outfile3 = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_hasReview.txt"

shoes = parseData.parse(outfile3)
reviews = parseData.parse(outfile2)

# find out flats that has price
flats = list()
for i in shoes:
    if i.has_key('price'):
        for k in i['categories']:
            for key in k:
                if key == "Flats":
                    flats.append(i)

len(flats)  # 2770

# prepare x and y; x is price, y is number of reviews
x = list()
y = list()
for i in flats:
    x.append(i['price'])
Beispiel #7
0
from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
from parseData import parse
from pybrain.structure import MDLSTMLayer, LinearLayer, SigmoidLayer, SoftmaxLayer, TanhLayer, GaussianLayer
import matplotlib.pyplot as plt
import random

#parsing data from file
dataSet = parse("data.csv")
random.shuffle(dataSet)
#shuffle(dataSet)
#parameters of network
net = buildNetwork(3, 20, 1, bias=True, hiddenclass=SigmoidLayer, outclass=SigmoidLayer)

#net = buildNetwork(3, 2, 1, bias=True, hiddenclass=SoftmaxLayer, outclass=LinearLayer)
print(net.modules)
#parameters of dataset and testSet
ds = SupervisedDataSet(3, 1)
ts = SupervisedDataSet(3, 1)
#Load data to training dataset
buf = []
for item in dataSet[2000:10000]:
    ds.addSample(item[0], item[1])

for item in dataSet[1000:2000]:
    ts.addSample(item[0], item[1])

trainer = BackpropTrainer(net, ds)
#training
for i in range(40):
import parseData
import analysis

import numpy
import matplotlib.pyplot
from scipy.stats import gaussian_kde

import operator

outfile2 = r"C:\Users\Yijun\Desktop\Amazon\reviews_shoes.txt"
outfile3 = r"C:\Users\Yijun\Desktop\Amazon\meta_shoes_hasReview.txt"

shoes = parseData.parse(outfile3)
reviews = parseData.parse(outfile2)

# find out flats that has price
flats = list()
for i in shoes:
  if i.has_key('price'):
    for k in i['categories']:
      for key in k:
        if key == "Flats":
          flats.append(i)

len(flats)		# 2770

# prepare x and y; x is price, y is number of reviews
x = list()
y = list()
for i in flats:
  x.append(i['price'])