-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalfredMath.py
More file actions
63 lines (53 loc) · 1.36 KB
/
alfredMath.py
File metadata and controls
63 lines (53 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys, json, subprocess, numpy, re
def splitInput(query):
theList = re.split(r'\D+', query)
theList = list(filter(None, theList))
return theList
def sumList(inList):
outNumber = 0
for num in inList:
outNumber += num
return outNumber
def avgList(inList):
outNumber = 0
count = len(inList)
for num in inList:
outNumber += num
return outNumber/count
def stdDeviation(inList):
return numpy.std(numpy.array(inList).astype(numpy.float))
args = subprocess.check_output("pbpaste", universal_newlines=True)
outSum = sumList(splitInput(args))
outAvg = avgList(splitInput(args))
outDev = stdDeviation(splitInput(args))
sumString = "The sum = {}".format(outSum)
avgString = "The average = {}".format(outAvg)
devString = "The average = {}".format(outDev)
result = {"items": [
{
"uid": "maths",
"title": "Sum",
"subtitle": sumString,
"arg": outSum,
},
{
"uid": "maths",
"title": "Average",
"subtitle": avgString,
"arg": outAvg,
},
{
"uid": "maths",
"title": "Standard Deviation",
"subtitle": devString,
"arg": outDev,
},
{
"uid": "maths",
"title": "distribution",
"subtitle": json.dumps(splitInput(args)),
"arg": json.dumps(splitInput(args)),
}
]}
finalResult = json.dumps(result)
print(finalResult)