-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArithemtic.js
More file actions
85 lines (73 loc) · 2.16 KB
/
Copy pathArithemtic.js
File metadata and controls
85 lines (73 loc) · 2.16 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
import React, { useRef } from 'react'
export default function Arithemtic({ dataComp, setDataComp}) {
const seriesOps = ["median", "min", "max", "std", "var", "count", "sum"]
const dfOps = ["cumsum", "cummax", "cumprod", "cummin"]
const all = ["median", "min", "max", "std", "var", "count", "sum",
"cumsum", "cummax", "cumprod", "cummin"]
const axisRef = useRef()
const opsRef = useRef()
const arithemtic = () => {
let sOps = opsRef.current.value
let axis = axisRef.current.value
// let df;
if( seriesOps.includes(sOps)) {
let df_comp = dataComp.df
let df = eval(`df_comp.${sOps}(axis=${axis})`)
let columns = Array.isArray(df.columns) ? df.columns.slice() : [df.columns]
columns.splice(0,0, "index")
let values = df.values.map((val,index) => {
return [df.index[index], val]
})
setDataComp(prev => {
let new_data = prev.slice()
let dict = {
columns: columns,
values: values,
df: df
}
new_data.push(dict)
return new_data
})
} else {
let df_comp2 = dataComp.df
let df = eval(`df_comp2.${sOps}({axis:${axis}})`)
setDataComp(prev => {
let new_data = prev.slice()
let dict = {
columns: df.columns,
values: df.values,
df: df
}
new_data.push(dict)
return new_data
})
}
}
return (
<div>
<form>
<div>
<span className="mr-2">Operation</span>
<select ref={opsRef} className="border">
{
all.map((val, index) => {
return <option value={val} key={index}>{val}</option>
})
}
</select>
</div>
<div>
<span>axis</span>
<select ref={axisRef} className="border">
{
[0,1].map((val, index) => {
return <option value={val} key={index}>{val}</option>
})
}
</select>
</div>
</form>
<button onClick={()=>arithemtic()} className="btn btn-default dq-btn-add">Submit</button>
</div>
)
}