Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace stats with eras client #6974

Merged
merged 10 commits into from
Dec 6, 2023
15 changes: 4 additions & 11 deletions app/pages/home-not-logged-in.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import statsClient from 'panoptes-client/lib/eras-client';
import Translate from 'react-translate-component';
import counterpart from 'counterpart';
import apiClient from 'panoptes-client/lib/api-client';
Expand All @@ -11,10 +12,6 @@ import HomePageSocial from './home-common/social';
import HomePageDiscover from './home-not-logged-in/discover';
import HomePageResearch from './home-not-logged-in/research';

const ERAS_STATS_URL = (process.env.NODE_ENV === 'staging' || process.env.NODE_ENV === 'development')
? 'https://eras-staging.zooniverse.org'
: 'https://eras.zooniverse.org';

counterpart.registerTranslations('en', {
notLoggedInHomePage: {
projects: 'See All Projects',
Expand Down Expand Up @@ -67,17 +64,13 @@ export default class HomePage extends React.Component {
}

getClassificationCounts() {
fetch(ERAS_STATS_URL + '/classifications').then((response) => {
if (!response.ok) {
console.error('ERAS STATS CLASSIFICATIONS COUNT NONLOGGED IN HOMEPAGE: ERROR')
throw Error(response.statusText);
}
return response.json()
statsClient.query({
type: 'classifications'
}).then(data => {
let count = data.total_count
this.setState({ count });
}).catch((err) => {
console.error('ERAS TOTAL CLASSIFICATION COUNT: from ' + ERAS_STATS_URL + '/classifications', err)
console.error('COULD NOT RETRIEVE ERAS TOTAL CLASSIFICATION COUNT', err)
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import statsClient from 'panoptes-client/lib/stats-client';
import statsClient from 'panoptes-client/lib/eras-client';

import fillTimeSeries from './helpers/fillTimeSeries';
import filterTimeSeries from './helpers/filterTimeSeries';
Expand Down Expand Up @@ -61,15 +61,15 @@ class BarChartContainer extends React.Component {
const query = {
period: binBy,
projectID,
type
type: type + 's'
mcbouslog marked this conversation as resolved.
Show resolved Hide resolved
};

return statsClient
.query(query)
.then(data => (
data.map(statObject => ({
label: statObject.key_as_string,
value: statObject.doc_count
data.data.map(statObject => ({
mcbouslog marked this conversation as resolved.
Show resolved Hide resolved
label: statObject.period,
value: statObject.count
}))
)).then(data => (
fillTimeSeries(data, binBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import formatLabel from '../helpers/formatLabel';
import Select from './Select';

export const binByOptions = [
{ label: 'hour', value: 'hour' },
{ label: 'day', value: 'day' },
{ label: 'week', value: 'week' },
{ label: 'month', value: 'month' }
Expand Down Expand Up @@ -177,12 +176,6 @@ function Parameters({
content="organization.stats.reset"
/>
</StyledResetButton>
{binBy === 'hour' && (
<Translate
component={StyledWarning}
content="organization.stats.hourly"
/>
)}
</StyledResetContainer>
</StyledParametersContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ describe('Parameters', function () {
.to.have.lengthOf(0);
});

it('should render hourly warning if binBy is hour', function () {
wrapper.setProps({ binBy: 'hour' });
expect(wrapper.find(Translate).filterWhere(n => n.prop('content') === 'organization.stats.hourly'))
.to.have.lengthOf(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ function fillTimeSeries(series = [], by = 'day', notEarlierThan = twoWeeksBefore
const filledSeries = [];
let previousLabel = '';
series.forEach(({ label, value }) => {
if (by === 'hour' && moment.utc(label) <= notEarlierThan) {
return;
}
const difference = moment.utc(label).diff(moment.utc(previousLabel), `${by}s`);

if (difference > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ describe('fillTimeSeries', function () {
it('should return a series including dates with zero value', function () {
expect(fillTimeSeries(mockDaySeries, 'day')).to.eql(mockDaySeriesFilled);
});

it('should return a series by hour not earlier than two weeks before now', function () {
const notEarlierThan = moment.utc('2019-01-09T03:00:00.000Z');
expect(fillTimeSeries(mockHourSeries, 'hour', notEarlierThan)).to.eql(mockHourSeriesFilled);
});
});
4 changes: 2 additions & 2 deletions app/pages/project/stats/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class ProjectStatsPageController extends React.Component {
handleGraphChange: this.handleGraphChange,
handleRangeChange: this.handleRangeChange,
handleWorkflowChange: this.handleWorkflowChange,
classificationsBy: this.getQuery('classification') || 'day',
classificationsBy: this.getQuery('classifications') || 'day',
classificationRange: this.getQuery('classificationRange'),
commentsBy: this.getQuery('comment') || 'day',
commentsBy: this.getQuery('comments') || 'day',
commentRange: this.getQuery('commentRange'),
projectId: this.props.project.id,
workflowId: this.getQuery('workflow_id'),
Expand Down
41 changes: 22 additions & 19 deletions app/pages/project/stats/stats.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import statsClient from 'panoptes-client/lib/stats-client';
import statsClient from 'panoptes-client/lib/eras-client';
import moment from 'moment';
import { Progress, Graph } from './charts.jsx';

Expand Down Expand Up @@ -41,17 +41,22 @@ export class GraphSelect extends React.Component {
}

getStats(workflowId, binBy) {
let queryObj = {
workflowID: workflowId,
period: binBy,
type: this.props.type,
}
if (this.props.type == 'comments' || workflowId == undefined) {
queryObj = {...queryObj,
projectID: this.props.projectId
}
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
}
statsClient
.query({
projectID: this.props.projectId,
workflowID: workflowId,
period: binBy,
type: this.props.type,
})
.query(queryObj)
.then((data) => (
data.map((statObject) => ({
label: statObject.key_as_string,
value: statObject.doc_count,
data.data.map((statObject) => ({
mcbouslog marked this conversation as resolved.
Show resolved Hide resolved
label: statObject.period,
value: statObject.count,
}))
))
.then((statData) => {
Expand Down Expand Up @@ -138,9 +143,8 @@ export class GraphSelect extends React.Component {
const workflowSelect = this.workflowSelect();
output = (
<div>
{this.props.type[0].toUpperCase() + this.props.type.substring(1)}s per{' '}
{this.props.type[0].toUpperCase() + this.props.type.substring(1)} per{' '}
<select value={this.props.by} onChange={this.handleGraphChange}>
<option value="hour">hour</option>
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
Expand Down Expand Up @@ -210,18 +214,17 @@ export class WorkflowProgress extends React.Component {
.query({
workflowID: this.props.workflow.id,
period: 'day',
type: 'classification',
type: 'classifications',
})
.then((data) => (
data.map((statObject) => (
statObject.doc_count
))
data.data.map((statObject) => statObject.count)
mcbouslog marked this conversation as resolved.
Show resolved Hide resolved
))
.then((statData) => {
this.setState({ statData });
})
.catch(() => {
.catch((e) => {
if (console) {
console.log(e)
console.warn('Failed to fetch stats');
}
});
Expand Down Expand Up @@ -416,7 +419,7 @@ export class ProjectStatsPage extends React.Component {
workflows={this.props.workflows}
failedWorkflows={this.props.failedWorkflows}
workflowId={this.props.workflowId}
type="classification"
type="classifications"
projectId={this.props.projectId}
by={this.props.classificationsBy}
range={this.props.classificationRange}
Expand All @@ -429,7 +432,7 @@ export class ProjectStatsPage extends React.Component {
<GraphSelect
handleGraphChange={this.props.handleGraphChange}
handleRangeChange={this.props.handleRangeChange}
type="comment"
type="comments"
projectId={this.props.projectId}
by={this.props.commentsBy}
range={this.props.commentRange}
Expand Down