Commit f6819f29 by OuiAtichat

api

parent 0ee1b091
......@@ -12,6 +12,7 @@
"moment": "^2.24.0",
"node-sass": "^4.12.0",
"prop-types": "^15.7.2",
"qs": "^6.7.0",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.10",
"react-bootstrap-daterangepicker": "^4.1.0",
......
......@@ -7,6 +7,7 @@ import DataCard from '../components/DataCard';
import GetDataSelection from '../components/GetDataSelection/GetDataSelection';
import Mapbox from '../components/Mapbox';
import axios from 'axios';
import qs from 'qs';
const Data = [
{
......@@ -76,6 +77,7 @@ class Home extends Component {
this.getCurrentUser();
this.getFeedData();
// this.getFireStoreData();
this.currentWeight();
}
getCurrentUser = async () => {
......@@ -98,7 +100,35 @@ class Home extends Component {
'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 });
console.log(response.data.metrics[0].value);
};
currentWeight = async (ctx = '', traceback = '1y') => {
// let device_id = ctx.device_id;
let device_id = '3d2951a5-fa10-4d56-abae-bc471f3d2e1f';
let q_data = qs.stringify({ device_id, traceback });
console.log(q_data);
const userToken =
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdHgiOnsib3duZXIiOiJVNDY0NzAxMzI2MjYwIn0sInNjb3BlIjpbXSwiaWF0IjoxNTY0OTc3MTY4LCJuYmYiOjE1NjQ5NzcxNjgsImV4cCI6MTYyODE0NDg5MSwiZXhwaXJlSW4iOjYzMTY3NzIzLCJqdGkiOiI3QzRNNUY1VyIsImlzcyI6ImNlcjp1c2VydG9rZW4ifQ.B0zXLSlsUucj4ohvH4lNVectCAt4hk--qMPEv-qhCUu82puCnNMsK2ZnnPeO_KE3up-vqVsjMVxLQ2jvmuspNg';
const kairos_url = 'https://feed.nexpie.io/api/v1/datapoints/query';
const options = {
url: kairos_url,
medthod: 'get',
headers: { 'Content-Type': 'application/json' },
data: q_data,
auth: {
username: userToken,
password: '',
},
};
try {
// const response = await axios.post(kairos_url, options);
const response = await axios(options);
console.log(response);
} catch (error) {
console.error(error);
}
};
render() {
......
......@@ -6,37 +6,6 @@ import withWindowDimensions from '../utils/withWindowDimensions';
import { CSVLink } from 'react-csv';
import moment from 'moment';
// const chartdata = [
// {
// name: 'Page A',
// uv: 4000,
// },
// {
// name: 'Page B',
// uv: 3000,
// },
// {
// name: 'Page C',
// uv: 2000,
// },
// {
// name: 'Page D',
// uv: 2780,
// },
// {
// name: 'Page E',
// uv: 1890,
// },
// {
// name: 'Page F',
// uv: 2390,
// },
// {
// name: 'Page G',
// uv: 3490,
// },
// ];
const SmCard = props => {
const smdata = props.smitem;
const iconStyle = { style: { height: '1.5em', width: '1.5em' } };
......@@ -66,7 +35,11 @@ const SmCard = props => {
const DataCard = props => {
const data = props.item;
console.log(props.feedData);
if (props.feedData) {
var dataObj = props.feedData.map(value => ({ xAxis: moment(value[0]).format('DD MMM YY'), yAxis: value[1] }));
// console.log(dataObj);
}
return (
<Col md={6}>
<Card
......@@ -81,7 +54,7 @@ const DataCard = props => {
<div style={{ width: '100%', height: 300, padding: '5px' }}>
<ResponsiveContainer>
<AreaChart
data={props.feedData}
data={dataObj}
margin={{
top: 10,
right: 30,
......@@ -89,30 +62,9 @@ const DataCard = props => {
bottom: 0,
}}
>
{/* <XAxis stroke="white" dataKey="name" tick={{ fill: 'white' }} />
<YAxis stroke="white" tick={{ fill: 'white' }} /> */}
<XAxis
stroke="white"
dataKey={value => {
return moment(value[0]).format('DD MMM YY');
}}
tick={{ fill: 'white' }}
/>
<YAxis
stroke="white"
dataKey={value => {
return value[1];
}}
tick={{ fill: 'white' }}
/>
<Area
type="monotone"
dataKey={value => {
return value[1];
}}
stroke="white"
fill="white"
/>
<XAxis stroke="white" dataKey="xAxis" tick={{ fill: 'white' }} />
<YAxis stroke="white" dataKey="yAxis" tick={{ fill: 'white' }} />
<Area type="monotone" dataKey="yAxis" stroke="white" fill="white" />
</AreaChart>
</ResponsiveContainer>
</div>
......
......@@ -9007,7 +9007,7 @@ q@^1.1.2:
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
qs@6.7.0:
qs@6.7.0, qs@^6.7.0:
version "6.7.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment