Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
toiletcoin
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
atichat
toiletcoin
Commits
c84d5bb8
Commit
c84d5bb8
authored
Aug 06, 2019
by
OuiAtichat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
df4de448
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
80 deletions
+92
-80
src/Pages/Home.js
+67
-65
src/components/DataCard.js
+7
-4
src/components/GetDataSelection/DateRangeSeletion.js
+0
-1
src/components/GetDataSelection/GetDataSelection.js
+18
-10
No files found.
src/Pages/Home.js
View file @
c84d5bb8
import
React
,
{
Component
}
from
'react'
;
import
app
,
{
db
}
from
'../firebase'
;
import
{
Row
,
Container
}
from
'react-bootstrap'
;
import
{
Row
,
Container
,
Col
}
from
'react-bootstrap'
;
import
DataTable
from
'../components/DataTable'
;
import
NavBar
from
'../components/NavBar'
;
import
DataCard
from
'../components/DataCard'
;
import
DataCard
,
{
SmCard
}
from
'../components/DataCard'
;
import
GetDataSelection
from
'../components/GetDataSelection/GetDataSelection'
;
import
Mapbox
from
'../components/Mapbox'
;
import
axios
from
'axios'
;
...
...
@@ -13,56 +13,56 @@ const Data = [
{
title
:
'Current chart'
,
backgroundColor
:
'#51ABAD'
,
detail
:
[{
smtitle
:
'Total current'
,
sm
number
:
0
,
iconType
:
'money'
}],
detail
:
[{
smtitle
:
'Total current'
,
sm
Value
:
18.
0
,
iconType
:
'money'
}],
},
{
title
:
'Revenue chart'
,
backgroundColor
:
'#51ABAD'
,
detail
:
[
{
smtitle
:
'Total revenue'
,
sm
number
:
18.0
,
iconType
:
'money'
},
{
smtitle
:
'Avg. revenue'
,
sm
number
:
17.53
,
iconType
:
'money'
},
{
smtitle
:
'Max. Revenue'
,
sm
number
:
18.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Revenue'
,
sm
number
:
17.0
,
iconType
:
'min'
},
{
smtitle
:
'Total revenue'
,
sm
Value
:
18.0
,
iconType
:
'money'
},
{
smtitle
:
'Avg. revenue'
,
sm
Value
:
17.53
,
iconType
:
'money'
},
{
smtitle
:
'Max. Revenue'
,
sm
Value
:
18.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Revenue'
,
sm
Value
:
17.0
,
iconType
:
'min'
},
],
},
{
title
:
'People chart'
,
backgroundColor
:
'#5E73F6'
,
detail
:
[
{
smtitle
:
'Total People'
,
sm
number
:
1105.0
},
{
smtitle
:
'Avg. People'
,
sm
number
:
3320.53
},
{
smtitle
:
'Max. People'
,
sm
number
:
4635.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. People'
,
sm
number
:
0
,
iconType
:
'min'
},
{
smtitle
:
'Total People'
,
sm
Value
:
1105.0
},
{
smtitle
:
'Avg. People'
,
sm
Value
:
3320.53
},
{
smtitle
:
'Max. People'
,
sm
Value
:
4635.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. People'
,
sm
Value
:
0
,
iconType
:
'min'
},
],
},
{
title
:
'Remote chart'
,
backgroundColor
:
'#5E73F6'
,
detail
:
[
{
smtitle
:
'Total Remote'
,
sm
number
:
0
},
{
smtitle
:
'Avg. Remote'
,
sm
number
:
0
},
{
smtitle
:
'Max. Remote'
,
sm
number
:
0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Remote'
,
sm
number
:
0
,
iconType
:
'min'
},
{
smtitle
:
'Total Remote'
,
sm
Value
:
0
},
{
smtitle
:
'Avg. Remote'
,
sm
Value
:
0
},
{
smtitle
:
'Max. Remote'
,
sm
Value
:
0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Remote'
,
sm
Value
:
0
,
iconType
:
'min'
},
],
},
{
title
:
'Fingerprint chart'
,
backgroundColor
:
'#5E73F6'
,
detail
:
[
{
smtitle
:
'Total Fingerprint'
,
sm
number
:
1105.0
},
{
smtitle
:
'Avg. Fingerprint'
,
sm
number
:
3320.53
},
{
smtitle
:
'Max. Fingerprint'
,
sm
number
:
4635.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Fingerprint'
,
sm
number
:
0
,
iconType
:
'min'
},
{
smtitle
:
'Total Fingerprint'
,
sm
Value
:
1105.0
},
{
smtitle
:
'Avg. Fingerprint'
,
sm
Value
:
3320.53
},
{
smtitle
:
'Max. Fingerprint'
,
sm
Value
:
4635.0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Fingerprint'
,
sm
Value
:
0
,
iconType
:
'min'
},
],
},
{
title
:
'Keycard chart'
,
backgroundColor
:
'#5E73F6'
,
detail
:
[
{
smtitle
:
'Total Keycard'
,
sm
number
:
0
},
{
smtitle
:
'Avg. Keycard'
,
sm
number
:
0
},
{
smtitle
:
'Max. Keycard'
,
sm
number
:
0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Keycard'
,
sm
number
:
0
,
iconType
:
'min'
},
{
smtitle
:
'Total Keycard'
,
sm
Value
:
0
},
{
smtitle
:
'Avg. Keycard'
,
sm
Value
:
0
},
{
smtitle
:
'Max. Keycard'
,
sm
Value
:
0
,
iconType
:
'max'
},
{
smtitle
:
'Min. Keycard'
,
sm
Value
:
0
,
iconType
:
'min'
},
],
},
];
...
...
@@ -72,19 +72,18 @@ class Home extends Component {
userToken
:
null
,
kairosUrl
:
null
,
currentUser
:
null
,
feedData
:
null
,
};
// constructor(props) {
// super(props);
// // Don't call this.setState() here!
// this.state = { userToken: null, kairosUrl: null, currentUser: null, feedData: null };
// }
currentFeed
:
null
,
currentDetail
:
null
,
revenueFeed
:
null
,
peopleFeed
:
null
,
remoteFeed
:
null
,
fingerPrintFeed
:
null
,
keycardFeed
:
null
,
};
async
componentDidMount
()
{
await
this
.
getFireStoreData
();
this
.
getCurrentUser
();
// await this.getFeedData();
}
...
...
@@ -93,6 +92,7 @@ class Home extends Component {
const
configData
=
await
db
.
collection
(
'config'
).
get
();
//get all data from collection 'config'
configData
.
forEach
(
doc
=>
{
console
.
log
(
doc
.
data
());
this
.
setState
({
kairosUrl
:
doc
.
data
().
kairosUrl
,
userToken
:
doc
.
data
().
userToken
,
...
...
@@ -105,36 +105,14 @@ class Home extends Component {
this
.
setState
({
currentUser
:
displayName
||
email
});
};
// getFeedData = async () => {
// const response = await axios.get(
// 'https://api.nexpie.io/feed/metric/11add2ec-89e7-4985-8525-b0421896b7a2?token=eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdHgiOnsib3duZXIiOiJVNDMwMDQ1Mzc3ODY2In0sInNjb3BlIjpbXSwiaWF0IjoxNTU3MjIzOTQwLCJuYmYiOjE1NTcyMjM5NDAsImV4cCI6MTYyMDMzOTE0MCwiZXhwaXJlSW4iOjYzMTE1MjAwLCJqdGkiOiJua1NKcHMyMSIsImlzcyI6ImNlcjp1c2VydG9rZW4ifQ.1I2m6qdNxPzicYNRuKrFOp-Jn9DaSfV0pdAyDtjD7-BOZzRmsqBeIUWxmE24MQWIFlGXuDXq0tLxvBtiEdySBA&starttime=1564938060076&endtime=1565024340076'
// );
// this.setState({ feedData: response.data.metrics[0].value });
// };
// queryGenerator = (device_id, selectedRange) => {
// // let now = endtime ? endtime : new Date().getTime();
// // console.log(now);
// // console.log(moment().valueOf());
// // const { startDate, endDate } = selectedRange;
// // console.log(startDate, endDate);
// let q_data = ;
// return q_data;
// };
getFeedData
=
async
(
deviceId
,
selectedRange
=
{
startDate
:
moment
().
valueOf
(),
endDate
:
moment
().
valueOf
()
},
breakdown
)
=>
{
getFeedData
=
async
(
deviceId
,
selectedRange
,
breakdown
)
=>
{
const
{
kairosUrl
,
userToken
}
=
this
.
state
;
const
{
startDate
,
endDate
}
=
selectedRange
;
const
now
=
moment
().
valueOf
();
// let q_data = this.queryGenerator(deviceId, selectedRange);
// let now = new Date().getTime();
let
q_data
=
{
start_absolute
:
startDate
,
end_absolute
:
endDate
,
start_absolute
:
startDate
||
now
,
end_absolute
:
endDate
||
now
,
metrics
:
[
{
name
:
deviceId
,
...
...
@@ -151,8 +129,8 @@ class Home extends Component {
{
name
:
'avg'
,
sampling
:
{
value
:
1
000
,
unit
:
'milliseconds'
,
value
:
1
,
unit
:
breakdown
,
},
},
],
...
...
@@ -164,35 +142,59 @@ class Home extends Component {
try
{
const
response
=
await
axios
.
post
(
kairosUrl
,
q_data
);
console
.
log
(
response
.
data
.
queries
[
0
].
results
);
this
.
setState
({
currentFeed
:
response
.
data
.
queries
[
0
].
results
[
5
].
values
,
revenueFeed
:
response
.
data
.
queries
[
0
].
results
[
4
].
values
,
peopleFeed
:
response
.
data
.
queries
[
0
].
results
[
3
].
values
,
remoteFeed
:
response
.
data
.
queries
[
0
].
results
[
2
].
values
,
keycardFeed
:
response
.
data
.
queries
[
0
].
results
[
1
].
values
,
fingerPrintFeed
:
response
.
data
.
queries
[
0
].
results
[
0
].
values
,
});
console
.
log
(
response
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
};
handleConfirm
=
selectedFeed
=>
{
getSelectedFeed
=
selectedFeed
=>
{
console
.
log
(
selectedFeed
);
const
{
device
,
range
,
breakdown
}
=
selectedFeed
;
this
.
getFeedData
(
device
,
range
,
breakdown
);
};
render
()
{
const
{
currentUser
,
feedData
}
=
this
.
state
;
const
{
currentUser
,
currentFeed
,
revenueFeed
,
peopleFeed
,
remoteFeed
,
fingerPrintFeed
,
keycardFeed
,
}
=
this
.
state
;
return
(
<>
<
NavBar
user
=
{
currentUser
}
/
>
<
Container
style
=
{{
padding
:
'30px'
,
maxWidth
:
'990px'
}}
>
<
Row
>
<
GetDataSelection
onConfirm
=
{
this
.
handleConfirm
}
/
>
<
GetDataSelection
onConfirm
=
{
this
.
getSelectedFeed
}
/
>
<
/Row
>
<
Row
>
<
Mapbox
/>
<
/Row
>
<
Row
>
{
Data
.
map
((
item
,
index
)
=>
(
{
/* {
Data.map((item, index) => (
<DataCard key={index} item={item} feedData={feedData} />
))}
))} */
}
<
DataCard
item
=
{
Data
[
0
]}
feedData
=
{
currentFeed
}
/
>
<
DataCard
item
=
{
Data
[
1
]}
feedData
=
{
revenueFeed
}
/
>
<
DataCard
item
=
{
Data
[
2
]}
feedData
=
{
peopleFeed
}
/
>
<
DataCard
item
=
{
Data
[
3
]}
feedData
=
{
remoteFeed
}
/
>
<
DataCard
item
=
{
Data
[
5
]}
feedData
=
{
fingerPrintFeed
}
/
>
<
DataCard
item
=
{
Data
[
4
]}
feedData
=
{
keycardFeed
}
/
>
<
/Row
>
<
Row
>
<
DataTable
/>
...
...
src/components/DataCard.js
View file @
c84d5bb8
import
React
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
{
Card
,
Col
,
Row
,
Button
,
Tooltip
}
from
'react-bootstrap'
;
import
{
FaMoneyBillAlt
,
FaArrowUp
,
FaArrowDown
,
FaUserFriends
,
FaFileCsv
}
from
'react-icons/fa'
;
import
{
AreaChart
,
Area
,
XAxis
,
YAxis
,
ResponsiveContainer
}
from
'recharts'
;
...
...
@@ -6,7 +6,7 @@ import withWindowDimensions from '../utils/withWindowDimensions';
import
{
CSVLink
}
from
'react-csv'
;
import
moment
from
'moment'
;
const
SmCard
=
props
=>
{
export
const
SmCard
=
props
=>
{
const
smdata
=
props
.
smitem
;
const
iconStyle
=
{
style
:
{
height
:
'1.5em'
,
width
:
'1.5em'
}
};
return
(
...
...
@@ -25,7 +25,7 @@ const SmCard = props => {
)}
<
/Col
>
<
Col
>
<
h2
style
=
{{
textAlign
:
'right'
}}
>
{
smdata
.
sm
number
}
<
/h2
>
<
h2
style
=
{{
textAlign
:
'right'
}}
>
{
smdata
.
sm
Value
}
<
/h2
>
<
/Col
>
<
/Row
>
<
/Card
>
...
...
@@ -36,7 +36,10 @@ const DataCard = props => {
const
data
=
props
.
item
;
if
(
props
.
feedData
)
{
var
dataObj
=
props
.
feedData
.
map
(
value
=>
({
xAxis
:
moment
(
value
[
0
]).
format
(
'DD MMM YY'
),
yAxis
:
value
[
1
]
}));
var
dataObj
=
props
.
feedData
.
map
(
value
=>
({
xAxis
:
moment
(
value
[
0
]).
format
(
'D/M/YY h:mm:ss a'
),
yAxis
:
value
[
1
],
}));
// console.log(dataObj);
}
...
...
src/components/GetDataSelection/DateRangeSeletion.js
View file @
c84d5bb8
...
...
@@ -27,7 +27,6 @@ class PredefinedRanges extends Component {
};
// handleEvent = (event, picker) => {
// };
handleApply
=
(
event
,
picker
)
=>
{
...
...
src/components/GetDataSelection/GetDataSelection.js
View file @
c84d5bb8
import
React
,
{
Component
}
from
'react'
;
import
{
Col
,
Form
,
Button
}
from
'react-bootstrap'
;
import
DateRangeSeletion
from
'./DateRangeSeletion'
;
import
moment
from
'moment'
;
class
GetDataSelection
extends
Component
{
state
=
{
device
:
''
,
range
:
[],
breakdown
:
'minute'
,
device
:
'3d2951a5-fa10-4d56-abae-bc471f3d2e1f'
,
range
:
{
startDate
:
moment
()
.
subtract
(
1
,
'days'
)
.
valueOf
(),
endDate
:
moment
().
valueOf
(),
},
breakdown
:
'minutes'
,
};
handleClickGo
=
e
=>
{
this
.
props
.
onConfirm
&&
this
.
props
.
onConfirm
(
this
.
state
);
};
handle
SelectedRange
=
selectedRange
=>
{
get
SelectedRange
=
selectedRange
=>
{
this
.
setState
({
range
:
selectedRange
});
};
...
...
@@ -25,6 +31,7 @@ class GetDataSelection extends Component {
<
Col
md
>
<
Form
.
Control
as
=
"select"
defaultValue
=
{
this
.
state
.
device
}
onChange
=
{
e
=>
{
console
.
log
(
e
.
target
.
value
);
this
.
setState
({
device
:
e
.
target
.
value
});
...
...
@@ -36,21 +43,22 @@ class GetDataSelection extends Component {
<
/Form.Control
>
<
/Col
>
<
Col
md
>
<
DateRangeSeletion
selectedRange
=
{
this
.
handle
SelectedRange
}
/
>
<
DateRangeSeletion
selectedRange
=
{
this
.
get
SelectedRange
}
/
>
<
/Col
>
<
Col
md
=
{
3
}
>
<
Form
.
Control
as
=
"select"
defaultValue
=
{
this
.
state
.
breakdown
}
onChange
=
{
e
=>
{
console
.
log
(
e
.
target
.
value
);
this
.
setState
({
breakdown
:
e
.
target
.
value
});
}}
>
<
option
value
=
"minute"
>
Breakdown
by
minute
<
/option
>
<
option
value
=
"hour"
>
Breakdown
by
hour
<
/option
>
<
option
value
=
"day"
>
Breakdown
by
day
<
/option
>
<
option
value
=
"week"
>
Breakdown
by
week
<
/option
>
<
option
value
=
"month"
>
Breakdown
by
month
<
/option
>
<
option
value
=
"minute
s
"
>
Breakdown
by
minute
<
/option
>
<
option
value
=
"hour
s
"
>
Breakdown
by
hour
<
/option
>
<
option
value
=
"day
s
"
>
Breakdown
by
day
<
/option
>
<
option
value
=
"week
s
"
>
Breakdown
by
week
<
/option
>
<
option
value
=
"month
s
"
>
Breakdown
by
month
<
/option
>
<
/Form.Control
>
<
/Col
>
<
Col
md
=
{
1
}
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment