Skip to content

Commit 6b07976

Browse files
Андрей ЕлисеевАндрей Елисеев
authored andcommitted
Conflict merge
2 parents b8734e0 + f91de9b commit 6b07976

24 files changed

+487
-333
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ src/server/api/__pycache__
1616
start_env.sh
1717
*.DS_Store
1818

19-
/src/server/venv/
19+
/src/server/venv/
20+
/src/local_files/

src/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ In server:
4444
Brutally clean all docker related items from your machine
4545
--------------------------
4646
`docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker network prune -f && docker rmi -f $(docker images --filter dangling=true -qa) && docker volume rm $(docker volume ls --filter dangling=true -q) && docker rmi -f $(docker images -qa)`
47+
48+
--------------------------
49+
Troubleshooting
50+
---------------------------------------
51+
See the [Troubleshooting page](https://github.com/CodeForPhilly/paws-data-pipeline/wiki/Troubleshooting) at the GitHub wiki.

src/client/src/pages/Admin.js

Lines changed: 112 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React, { Component } from 'react';
2-
import {Tabs, Tab, Container, Paper } from "@material-ui/core";
2+
import {Tabs, Tab, Paper } from "@material-ui/core";
33
import TabPanel from '../components/TabPanel';
44
import Grid from '@material-ui/core/Grid';
5+
import Table from '@material-ui/core/Table';
6+
import TableBody from '@material-ui/core/TableBody';
7+
import TableCell from '@material-ui/core/TableCell';
8+
import TableContainer from '@material-ui/core/TableContainer';
9+
import TableHead from '@material-ui/core/TableHead';
10+
import TableRow from '@material-ui/core/TableRow';
511
import { withStyles } from '@material-ui/core/styles';
6-
import Divider from '@material-ui/core/Divider';
712
import LinearProgress from '@material-ui/core/LinearProgress';
813
import CircularProgress from '@material-ui/core/CircularProgress';
914
import { UploadForm, DownloadForm, ExecuteForm } from '../components/Forms';
@@ -27,19 +32,27 @@ class Admin extends Component {
2732
activeIndex: 0,
2833
loading: false,
2934
loadingCurrentFiles: false,
30-
fileList: undefined,
35+
loadingStatistics: false,
36+
statistics: [],
3137
filesInput: undefined,
32-
fileListHtml: undefined
38+
fileListHtml: undefined,
39+
lastExecution: undefined
3340
}
3441

3542
this.handleIndexChange = this.handleIndexChange.bind(this);
3643
this.handleUpload = this.handleUpload.bind(this);
3744
this.handleExecute = this.handleExecute.bind(this);
3845
this.handleGetFileList = this.handleGetFileList.bind(this);
46+
this.handleGetStatistics = this.handleGetStatistics.bind(this);
3947
}
4048

41-
componentDidMount(){
49+
refreshPage() {
4250
this.handleGetFileList();
51+
this.handleGetStatistics();
52+
}
53+
54+
componentDidMount(){
55+
this.refreshPage();
4356
}
4457

4558
handleIndexChange(event, newIndex){
@@ -67,32 +80,63 @@ class Admin extends Component {
6780

6881
async handleExecute(event) {
6982
event.preventDefault();
83+
// TODO: it looks like it handles it, but may want to tie events into stats too (like set loadingStatistics: true)
7084
this.setState({loading: true});
7185

7286
const response = await fetch('/api/execute');
7387
const result = await response.json();
7488

7589
this.setState({loading: false});
7690

91+
this.refreshPage();
92+
7793
return result
7894
}
7995

96+
async handleGetStatistics() {
97+
this.setState({loadingStatistics: true})
98+
99+
try {
100+
const statsData = await fetch("/api/statistics");
101+
const statsResponse = await statsData.json();
102+
103+
this.setState({
104+
statistics: _.toPairsIn(statsResponse.stats),
105+
lastExecution: statsResponse.executionTime
106+
});
107+
108+
console.log("statisticsListHtml", this.state.statistics);
109+
// this.setState({statisticsListHtml: stats});
110+
this.setState({loadingStatistics: false})
111+
}
112+
finally {
113+
this.setState({loadingStatistics: false})
114+
}
115+
116+
}
117+
80118
async handleGetFileList() {
81119
this.setState({loadingCurrentFiles: true})
82120

83-
const filesData = await fetch("/api/listCurrentFiles");
84-
const filesResponse = await filesData.json();
121+
try{
122+
const filesData = await fetch("/api/listCurrentFiles");
123+
const filesResponse = await filesData.json();
85124

86-
this.setState({fileList: filesResponse});
125+
// this.setState({fileList: filesResponse});
87126

88-
this.setState({fileListHtml: _.map(filesResponse, (fileName) => {
89-
return <li key={fileName}> {fileName}</li>
90-
})});
127+
this.setState({fileListHtml: _.map(filesResponse, (fileName) => {
128+
return (<li key={fileName}> {fileName}</li>)
129+
})});
130+
131+
console.log("fileListHtml", this.state.fileListHtml);
132+
//just a UX indication that a new list has been loaded
133+
//await new Promise(resolve => setTimeout(resolve, 1000));
134+
}
91135

92-
//just a UX indication that a new list has been loaded
93-
await new Promise(resolve => setTimeout(resolve, 1000));
136+
finally {
137+
this.setState({loadingCurrentFiles: false})
138+
}
94139

95-
this.setState({loadingCurrentFiles: false})
96140
}
97141

98142
render() {
@@ -120,29 +164,65 @@ class Admin extends Component {
120164
<CircularProgress />
121165
</div>
122166
:
123-
<ul>{this.state.fileListHtml}</ul>
167+
<Paper style={{padding: 5}}>
168+
<ul>{this.state.fileListHtml}</ul>
169+
</Paper>
170+
171+
let currentStatistics = this.state.loadingStatistics === true ?
172+
<div className={classes.spinner}>
173+
<CircularProgress />
174+
</div>
175+
: _.isEmpty(this.state.statistics) !== true &&
176+
<TableContainer component={Paper} className="statisticsData">
177+
<Table aria-label="simple table" className={classes.table}>
178+
<TableHead>
179+
<TableRow>
180+
<TableCell>Sources Matched</TableCell>
181+
<TableCell align="left">Number of Matches</TableCell>
182+
</TableRow>
183+
</TableHead>
184+
<TableBody>
185+
{this.state.statistics.map((row) => (
186+
<TableRow key={row[0]}>
187+
<TableCell align="left" component="th" scope="row">
188+
{row[0]}
189+
</TableCell>
190+
<TableCell align="left">{row[1]}</TableCell>
191+
</TableRow>
192+
))}
193+
</TableBody>
194+
</Table>
195+
</TableContainer>
124196

125197
return (
126-
<Container>
127-
<h2>Admin Options</h2>
128-
<Paper elevation={2} style={{"marginTop":"1em", "padding":"2em"}}>
129-
<Grid container spacing={5}>
130-
<Grid item>
131-
<Tabs value={this.state.activeIndex} onChange={this.handleIndexChange}>
132-
<Tab label="Upload" />
133-
<Tab label="Download" />
134-
<Tab label="Execute" />
135-
</Tabs>
136-
{currentTabWithState}
137-
<Divider orientation="vertical" flexItem />
198+
<div>
199+
<h2>Admin Portal</h2>
200+
<Grid container spacing={3} direction="column" style={{padding:30}}>
201+
<Grid container spacing={3} direction="row">
202+
<Grid item sm={5} >
203+
<h3>Options</h3>
204+
<Paper style={{padding: 5}}>
205+
<Tabs value={this.state.activeIndex} onChange={this.handleIndexChange}>
206+
<Tab label="Upload" />
207+
<Tab label="Download" />
208+
<Tab label="Execute" />
209+
</Tabs>
210+
{currentTabWithState}
211+
</Paper>
212+
</Grid>
213+
<Grid item sm={4}>
214+
<h3>Current Files</h3>
215+
{currentListWithState}
216+
</Grid>
138217
</Grid>
139-
<Grid item>
140-
<h3>Current Files</h3>
141-
{currentListWithState}
218+
<Grid container spacing={3} direction="row">
219+
<Grid item sm={4}>
220+
<h3>Matching Stats from last Execution: {this.state.lastExecution}</h3>
221+
{currentStatistics}
222+
</Grid>
142223
</Grid>
143224
</Grid>
144-
</Paper>
145-
</Container>
225+
</div>
146226
);
147227
}
148228
}

src/client/src/pages/DataView360/DataView360.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class DataView360 extends Component {
5757
render(){
5858
const { classes } = this.props;
5959

60-
//temporary taking the first pet row in petpoint - todo: change to list
6160
return(
6261
<Container>
6362
<SearchBar participant={this.state.participant}
@@ -67,7 +66,7 @@ class DataView360 extends Component {
6766
<Paper className={styles.main} elevation={1} style={{"padding":"1em"}}>
6867
<ContactInfo participant={_.get(this.state, "participantData.salesforcecontacts")} />
6968
<Donations donations={_.get(this.state, 'participantData.salesforcedonations')} />
70-
<Adoptions adoptions={_.get(this.state, 'participantData.petpoint')} />
69+
<Adoptions adoptions={_.get(this.state, 'participantData.shelterluvpeople')} />
7170
<Volunteer volunteer={_.get(this.state, 'participantData.volgistics.json')}
7271
volunteerShifts={_.get(this.state, 'participantData.volgistics_shifts_results')}/>
7372

src/client/src/pages/DataView360/components/Adoptions.js

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import { withStyles } from '@material-ui/core/styles';
44
import styles from "./styles/Adoptions.module.css";
55
import "./styles/table.css";
66
import _ from 'lodash';
7-
import moment from 'moment';
8-
9-
const ROWS_TO_SHOW = 3
107

118
/* I don't khow, how to remove it. So I changed background-color on 'initial' */
129
const StyledTableCell = withStyles((theme)=>({
@@ -24,52 +21,39 @@ const StyledTableRow = withStyles((theme)=>({
2421
}
2522
}))(TableRow);
2623

27-
class Adoptions extends Component {
28-
constructor(props) {
29-
super(props);
3024

31-
this.createRows = this.createRows.bind(this);
32-
}
3325

34-
createRows(adoptions){
35-
adoptions = _.map(adoptions, pet => {
36-
return pet.json;
37-
});
38-
const adoptionsSorted = _.sortBy(adoptions, 'outcome_date');
39-
const latestAdoptions = adoptionsSorted.slice(0,ROWS_TO_SHOW);
26+
class Adoptions extends Component {
4027

41-
const result = _.map(latestAdoptions, pet => {
42-
return(<StyledTableRow>
43-
<TableCell>{moment(pet.outcome_date).format("YYYY-MM-DD")}</TableCell>
44-
<TableCell>{pet.animal_name}</TableCell>
45-
<TableCell>{pet.animal_type}</TableCell>
46-
<TableCell>{pet.primary_breed}</TableCell>
47-
<TableCell>{pet.animal_num}</TableCell>
48-
<TableCell>{pet.age_group}</TableCell>
49-
</StyledTableRow>);
28+
getAnimalIds() {
29+
let result = [];
5030

51-
});
31+
let animal_ids = _.get(this.props, 'adoptions[0].animal_ids');
32+
if(animal_ids) {
33+
result = _.filter(animal_ids.split("'"), item => {
34+
return _.isNaN(_.parseInt(item)) !== true;
35+
})
36+
}
5237

5338
return result;
5439
}
5540

5641
render() {
57-
return (<Container className={styles.adoptions}>
58-
<Typography className={styles.adoptions_title} gutterBottom='true' variant='h4'>Adoption/Foster Records(Top 3)</Typography>
42+
// todo: update when we add pet info
43+
// todo: clean array of animal_id
44+
return (<Container className={styles.adoptions} style={{"marginTop":"1em"}}>
45+
<Typography className={styles.adoptions_title} variant='h4'>Adoption/Foster Records(Top 3)</Typography>
5946
<TableContainer className="main_table_container" style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
6047
<Table className="main_table">
6148
<TableHead>
6249
<TableRow>
63-
<StyledTableCell>Date of Adoption</StyledTableCell>
64-
<StyledTableCell>Name</StyledTableCell>
65-
<StyledTableCell>Type/Species</StyledTableCell>
66-
<StyledTableCell>Primary Breed</StyledTableCell>
67-
<StyledTableCell>Animal-Number</StyledTableCell>
68-
<StyledTableCell>Current Age</StyledTableCell>
50+
<StyledTableCell align="center">Number of Adoptions</StyledTableCell>
6951
</TableRow>
7052
</TableHead>
7153
<TableBody>
72-
{ this.props.adoptions && this.createRows(this.props.adoptions) }
54+
<StyledTableRow>
55+
<TableCell align="center"> {_.size(this.getAnimalIds())}</TableCell>
56+
</StyledTableRow>
7357
</TableBody>
7458
</Table>
7559
</TableContainer>

src/client/src/pages/DataView360/components/ContactInfo.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ class ContactInfo extends Component {
2020
let phone = _.isEmpty(phoneStr) ? '-' : phoneStr.split(" ").join("");
2121

2222
return (<Container className={styles.contact_info}>
23+
<Typography align='center' variant='h4'>Contact Info</Typography>
2324
<Paper variant='outlined' className={styles.contact_info_main} style={{padding:'1em'}}>
24-
<div>
25+
<div style={{"display":"flex", "justifyContent":"space-between"}}>
2526
<Typography className={styles.contact_info_name}>
27+
<span style={{'fontWeight':'600'}}>
28+
{'Name:\t'}
29+
</span>
2630
<span>
2731
{_.get(this.props, "participant.first_name")}{'\t'}
2832
{_.get(this.props, "participant.last_name")}

src/client/src/pages/DataView360/components/Donations.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Donations extends Component {
3939
donationsSorted = donationsSorted.reverse();
4040
const latestDonations = donationsSorted.slice(0,ROWS_TO_SHOW);
4141

42-
const result = _.map(latestDonations, donation => {
43-
return( <StyledTableRow>
42+
const result = _.map(latestDonations, (donation, index) => {
43+
return( <StyledTableRow key={index}>
4444
<TableCell>{donation.close_date}</TableCell>
4545
<TableCell>${donation.amount}</TableCell>
4646
<TableCell>{donation.type}</TableCell>
@@ -52,8 +52,8 @@ class Donations extends Component {
5252

5353
render() {
5454
return (
55-
<Container className={styles.donations} >
56-
<Typography className={styles.donations_title} gutterBottom='true' variant='h4'>Financial Support Activity(Top 3)</Typography>
55+
<Container className={styles.donations} style={{"marginTop":"1em"}}>
56+
<Typography className={styles.donations_title} variant='h4'>Financial Support Activity(Top 3)</Typography>
5757
<TableContainer className="main_table_container" style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
5858
<Table className="main_table">
5959
<TableHead>

0 commit comments

Comments
 (0)