-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
140 lines (124 loc) · 5.72 KB
/
main.py
File metadata and controls
140 lines (124 loc) · 5.72 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
import sys,os
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, 'lib'))
sys.path.append(os.path.join(parent_folder_path, 'plugin'))
from flowlauncher import FlowLauncher,FlowLauncherAPI
import statistics
import subprocess
def copy2clip(txt):
cmd = 'echo '+txt.strip()+'|clip'
return subprocess.check_call(cmd, shell=True)
class statis(FlowLauncher):
def query(self, query):
results = []
try:
if len(query.strip()) == 0:
results.append({
"Title": "Enter the value",
"SubTitle": " separated them by commas",
"IcoPath": "Images/app.png"})
else:
value = []
index = []
listQ=query.split(",")
for num in listQ:
value.append(float(num))
for num in sorted(value):
index.append(str(num))
sortT="Sorted numbers: " + ",".join(index)
sortV=",".join(index)
results.append({
"Title": sortT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [sortV], }})
nT="n: " + str(len(value))
nV= str(len(value))
results.append({
"Title": nT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [nV], }})
meanT="Mean: " + str(statistics.mean(value))
meanV=str(statistics.mean(value))
results.append({
"Title": meanT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [meanV], }})
medianV = statistics.median(value)
medianT = f"Median(Q2): {str(medianV)}"
results.append({
"Title": medianT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [str(medianV)], }})
modeT="Mode: "+ str(statistics.mode(value))
modeV=str(statistics.mode(value))
results.append({
"Title": modeT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [modeV], }})
minT="Minimum: "+ str(index[0])
minV= str(index[0])
results.append({
"Title": minT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [minV], }})
maxT="Maximum: "+ str(index[-1])
maxV= str(index[-1])
results.append({
"Title": maxT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [maxV], }})
rangeT="Range: "+ str(float(index[-1])-float(index[0]))
rangeV=str(float(index[-1])-float(index[0]))
results.append({
"Title": rangeT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [rangeV], }})
Q1_list = []
Q3_list = []
for number in value:
if number < medianV:
Q1_list.append(number)
elif number > medianV:
Q3_list.append(number)
q1V = str(statistics.median(Q1_list))
q1T= "Q1: "+ q1V
results.append({
"Title": q1T,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [q1V], }})
q3V= str(statistics.median(Q3_list))
q3T="Q3: "+ q3V
results.append({
"Title": q3T,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [q3V], }})
IqRT="IQR: "+ str(float(q3V)-float(q1V))
IqRV=str(float(q3V)-float(q1V))
results.append({
"Title": IqRT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [IqRV], }})
varianceT="Variance: "+ str(statistics.pvariance(value))
varianceV=str(statistics.pvariance(value))
results.append({
"Title": varianceT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [varianceV], }})
SdT="Standard deviation: "+ str(statistics.pstdev(value))
SdV=str(statistics.pstdev(value))
results.append({
"Title": SdT,
"IcoPath": "Images/app.png",
"JsonRPCAction": {"method": "copy", "parameters": [SdV], }})
except:
results.append({
"Title": "Invalid Notation",
"SubTitle": "Please, Verify and try again",
"IcoPath": "Images/app.png"})
return results
def copy(self, ans):
FlowLauncherAPI.show_msg("Copied to clipboard", copy2clip(ans))
if __name__ == "__main__":
statis()