-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
107 lines (84 loc) · 2.98 KB
/
application.py
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
class Application():
# select one column from the dataframe
@staticmethod
def selectone(df, one):
# context
context = Context()
context.add('df', df)
context.add('one', one)
# 构建表达式
dataframe = VarExpression('df')
var_one = VarExpression('one')
# 再构建变量来进行计算,看起来啰嗦,但这样构建多种不同表达式计算就变得简单
result = SelectoneExpression(dataframe, var_one)
return result.interpret(context)
# select one column from the dataframe and multiple a number
# @staticmethod
# def selectonemutiple(df, one):
# left, right = (one.split("*"))
# if left.isdigit():
# num, column = int(left), right
# else:
# num, column = int(right), left
# # context
# context = Context()
# context.add('df', df)
# context.add('num', num)
# context.add('column', column)
# # 构建表达式
# dataframe = VarExpression('df')
# var_num = VarExpression('num')
# var_column = VarExpression('column')
# # 再构建变量来进行计算,看起来啰嗦,但这样构建多种不同表达式计算就变得简单
# result = SelectonemutipleExpression(dataframe, var_column, var_num)
# return result.interpret(context)
@staticmethod
def selectmore(df, *columns):
if (len(columns) < 1):
return print("error, need a column name")
if (len(columns) == 1):
return Application.selectone(df, columns[0])
context = Context()
# 构建执行环境
for i, column in enumerate(columns):
context.add('column' + str(i), column)
context.add('df', df)
# get basedataframe data
basedataframe = Application.selectone(df, columns[0])
context.add('basedataframe', basedataframe)
# 构建表达式
dataframe = VarExpression('df')
baseframe = VarExpression('basedataframe')
# 如果数量超过1个则累加表达式再求值
for i in range(1, len(columns)):
next_expression = VarExpression('column' + str(i))
# 表达式不断累加
expression = SelectaddanotherExpression(
dataframe, baseframe, next_expression)
basedataframe = expression.interpret(context)
context.add('basedataframe', basedataframe)
return basedataframe
@staticmethod
def fromfile(filename):
pass
@staticmethod
def wherefilter(df, condition):
pass
@staticmethod
def groupby(df, column):
pass
@staticmethod
def having(df, condition):
pass
@staticmethod
def orderby(df, column):
pass
@staticmethod
def createtable(name, column):
pass
@staticmethod
def deletetable(name, column):
pass
@staticmethod
def inserttable(name, column):
pass