Beispiel #1
0
	def returnIntervals(self):
		topN = [int(arg) for arg in sys.argv[4].split(",")]
		#print(topN)
		path = sys.argv[1]
		data = csvToJson.parseCsv(path)
		gap = sys.argv[2].split(",")
		intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
		intervalIdx = [intervalIdxs[arg] for arg in sys.argv[3].split(",")]
		for i in range(len(intervalIdx)):
			if intervalIdx[i] == 3:
				gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
			else:
				gap[i] = int(gap[i])
		threshold = 0.1
		if len(sys.argv) == 6:
			threshold = float(sys.argv[5])
		return self.combineProduceIntervals(data, topN, gap, intervalIdx, threshold)
Beispiel #2
0
	def sendIntervals(self, data, gap, intervalIdx, topN, threshold="0.1"):
		topN = [int(arg) for arg in topN.split(",")]
		data = loads(data)
		gap = gap.split(",")
		intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
		intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
		for i in range(len(intervalIdx)):
			if intervalIdx[i] == 3:
				gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
			else:
				gap[i] = int(gap[i])
		threshold = float(threshold)
		res = self.combineProduceIntervals(data, topN, gap, intervalIdx, threshold)
		print("res", [len(x) for x in res])
		# print("res",flattenInts(res))
		# print("res",[x.toList() for x in res])
		res = [x.tolist() for x in res]
		return dumps(res)
Beispiel #3
0
 def returnIntervals(self,
                     data,
                     topN,
                     gap,
                     intervalIdx,
                     threshold="0.1"):
     topN = [int(arg) for arg in topN.split(",")]
     data = loads(data)
     gap = gap.split(",")
     intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
     intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
     for i in range(len(intervalIdx)):
         if intervalIdx[i] == 3:
             gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
         else:
             gap[i] = int(gap[i])
     threshold = float(threshold)
     return dumps(
         combineProduceIntervals(data, topN, gap, intervalIdx,
                                 threshold))
Beispiel #4
0
	def sendIntervals(self, data, gap, intervalIdx, topN, threshold="0.1"):
		# print("gap", gap)
		# print("intervalIdx", intervalIdx)
		# print("topN", topN)
		topN = [int(arg) for arg in topN.split(",")]
		data = loads(data)
		#print(data)
		gap = gap.split(",")
		intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
		intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
		for i in range(len(intervalIdx)):
			if intervalIdx[i] == 3:
				gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
			else:
				gap[i] = int(gap[i])
		threshold = float(threshold)
		intervals = self.combineProduceIntervals(data, topN, gap, intervalIdx, threshold)
		print("intervals",intervals)
		intsFlat = []
		for intLst in intervals:
			intsFlat += intLst.flatten().astype(int).tolist()
		return dumps(intsFlat)
Beispiel #5
0
	def parseElapsedTime(self, col):
		newCol = np.zeros(len(col))
		for i in range(len(newCol)):
			newCol[i] = csvToJson.elapsedTimeToSec(col[i])
		return newCol[:]
Beispiel #6
0
    def combineProduceIntervals(self, data, topN, gap, intervalIdx, threshold):
        topN = [int(arg) for arg in topN.split(",")]
        data = loads(data)
        gap = gap.split(",")
        intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
        intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
        for i in range(len(intervalIdx)):
            if intervalIdx[i] == 3:
                gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
            else:
                gap[i] = int(gap[i])
        threshold = float(threshold)
        self.reformatArray(data)
        data["data"][13] = self.parseColumn(data["data"][13], int)
        data["data"][9] = self.parseColumn(data["data"][9], int)
        data["data"][1] = self.parseColumn(data["data"][1], float)
        data["data"][3] = self.parseElapsedTime(data["data"][3])
        #note to self, I think there are cases where I am zeroing a "---" for power and it ruins the variance
        #also look into an alternative for variance that allows for one or two out liers without skewing the result?

        power = data["data"][13]
        filtPower = filterData(power)
        rises = getStep(1, filtPower, 0.15)
        falls = getStep(-1, filtPower, 0.2)  #- 1
        steps = np.hstack((rises, falls))
        steps = np.sort(steps)
        steps[steps >= len(power)] = len(power) - 1
        groupings = []
        for i in range(len(intervalIdx)):
            groupings.append([])
        sorted_orderings = []
        for i in range(len(groupings)):
            cur_sorted_orderings, cur_groupings = self.getSortedOrderings(
                falls, rises, intervalIdx[i], gap[i], data, filtPower,
                threshold, topN[i], i)
            groupings[i] = cur_groupings
            sorted_orderings += cur_sorted_orderings

        groupsToUse = []
        sorted_on_finish, opt = self.getBestSchedule(sorted_orderings)

        for i in range(len(opt[1])):
            interval = sorted_on_finish[opt[1][i]]
            grouping_idx = interval[3]
            groupsToUse += groupings[grouping_idx][interval[2]].tolist()

        return groupsToUse

        def printIntervals():
            topN = [int(arg) for arg in sys.argv[4].split(",")]
            print(topN)
            path = sys.argv[1]
            data = csvToJson.parseCsv(path)
            gap = sys.argv[2].split(",")
            intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
            intervalIdx = [intervalIdxs[arg] for arg in sys.argv[3].split(",")]
            for i in range(len(intervalIdx)):
                if intervalIdx[i] == 3:
                    gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
                else:
                    gap[i] = int(gap[i])
            threshold = 0.1
            if len(sys.argv) == 6:
                threshold = float(sys.argv[5])

            return combineProduceIntervals(data, topN, gap, intervalIdx,
                                           threshold)

        def returnIntervals(self,
                            data,
                            topN,
                            gap,
                            intervalIdx,
                            threshold="0.1"):
            topN = [int(arg) for arg in topN.split(",")]
            data = loads(data)
            gap = gap.split(",")
            intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
            intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
            for i in range(len(intervalIdx)):
                if intervalIdx[i] == 3:
                    gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
                else:
                    gap[i] = int(gap[i])
            threshold = float(threshold)
            return dumps(
                combineProduceIntervals(data, topN, gap, intervalIdx,
                                        threshold))

        def main():
            printIntervals()
Beispiel #7
0
	def combineProduceIntervals(self, data, topN, gap, intervalIdx, threshold="0.1"):
		topN = [int(arg) for arg in topN.split(",")]
		data = loads(data)
		gap = gap.split(",")
		intervalIdxs = {"strokes": 9, "distance": 1, "time": 3}
		intervalIdx = [intervalIdxs[arg] for arg in intervalIdx.split(",")]
		for i in range(len(intervalIdx)):
			if intervalIdx[i] == 3:
				gap[i] = csvToJson.elapsedTimeToSec("00:" + gap[i] + ".0")
			else:
				gap[i] = int(gap[i])
		threshold = float(threshold)
		self.reformatArray(data)
		data["data"][13] = self.parseColumn(data["data"][13], int)
		data["data"][9] = self.parseColumn(data["data"][9], int)
		data["data"][1] = self.parseColumn(data["data"][1], float)
		data["data"][3] = self.parseElapsedTime(data["data"][3])
		# start_time = time.time()

		#note to self, I think there are cases where I am zeroing a "---" for power and it ruins the variance
		#also look into an alternative for variance that allows for one or two out liers without skewing the result?


		power = data["data"][13]
		# sys.stdout.write(json.dumps(power.tolist()))
		# sys.stdout.flush()
		# return;
		filtPower = filterData(power)
		rises = getStep(1, filtPower, 0.15)
		falls = getStep(-1, filtPower, 0.2) #- 1
		steps = np.hstack((rises,falls))
		steps = np.sort(steps)
		steps[steps >= len(power)] = len(power) - 1

		# print(len(data["data"][9]))
		# print(len(data["data"][1]))
		# print(len(data["data"][3]))
		# print(len(data["data"][13]))
		# print(len(filtPower))

		# print("rises",rises)
		# print("falls",len(falls),falls)

		groupings = []
		for i in range(len(intervalIdx)):
			groupings.append([])
		# [[]] * len(intervalIdx)
		sorted_orderings = []
		for i in range(len(groupings)):
			cur_sorted_orderings, cur_groupings = self.getSortedOrderings(falls, rises, intervalIdx[i], gap[i], data, filtPower,threshold, topN[i], i)
			groupings[i] = cur_groupings
			# print("sorted_orderings", i, cur_sorted_orderings)
			sorted_orderings += cur_sorted_orderings

		groupsToUse = []
		sorted_on_finish, opt = self.getBestSchedule(sorted_orderings)
		# print(opt)
		# print(sorted_on_finish[opt[1][0]])
		# print(sorted_on_finish[opt[1][1]])
		# print()
		for i in range(len(opt[1])):
			interval = sorted_on_finish[opt[1][i]]
			grouping_idx = interval[3]
			groupsToUse += groupings[grouping_idx][interval[2]].tolist()

		# print("flattened groupings",np.array(groupsToUse).flatten())

		# print("--- %s seconds ---" % (time.time() - start_time))
		# plt.subplot(211)

		# plt.plot(data["data"][13],'-bD', markevery=np.array(groupsToUse).flatten().tolist())

		# plt.show()
		return dumps(groupsToUse)