Skip to content

Commit

Permalink
Merge pull request #171 from saltastro/number-parse
Browse files Browse the repository at this point in the history
Number parse
  • Loading branch information
hettlage authored May 10, 2021
2 parents 798d713 + 3a59300 commit eaea7e4
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/react-csv": "^1.1.1",
"apollo-cache-inmemory": "^1.0.0",
"apollo-client": "^2.0.1",
"apollo-client-preset": "^1.0.1",
Expand Down
47 changes: 45 additions & 2 deletions src/actions/statisticsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { queryStatistics } from '../api/graphQL'
import {
FETCH_STATISTICS_START,
FETCH_STATISTICS_PASS,
FETCH_STATISTICS_FAIL
FETCH_STATISTICS_FAIL,
FETCH_PARTNER_STATISTICS_PASS,
FETCH_PARTNER_STATISTICS_START,
FETCH_PARTNER_STATISTICS_FAIL
} from '../types'

function startFetchStatistics () {
Expand Down Expand Up @@ -33,7 +36,35 @@ export function fetchStatisticsPass (statistics) {
)
}

export default function fetchStatistics (semester, partner) {
function startFetchPartnerStatistics () {
return (
{
type: FETCH_PARTNER_STATISTICS_START
}
)
}

function fetchPartnerStatisticsFail (error) {
return (
{
type: FETCH_PARTNER_STATISTICS_FAIL,
payload: { error }
}
)
}

export function fetchPartnerStatisticsPass (partnerStatistics) {
return (
{
type: FETCH_PARTNER_STATISTICS_PASS,
payload: {
partnerStatistics
}
}
)
}

export function fetchStatistics (semester, partner) {
return function disp (dispatch) {
dispatch(startFetchStatistics())
queryStatistics(semester, partner)
Expand All @@ -43,4 +74,16 @@ export default function fetchStatistics (semester, partner) {
dispatch(fetchStatisticsFail(e.message))
})
}
}

export function fetchPartnerStatistics (semester, partner) {
return function disp (dispatch) {
dispatch(startFetchPartnerStatistics())
queryStatistics(semester, partner)
.then(res => { dispatch(fetchPartnerStatisticsPass(res)) }
)
.catch((e) => {
dispatch(fetchPartnerStatisticsFail(e.message))
})
}
}
6 changes: 5 additions & 1 deletion src/api/graphQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function requestedTime(requirements, semester){
})
return reqTime
}
const removeRejectedProposals = proposals => proposals.filter(proposal => proposal.status !== 'Rejected')

export function convertProposals(proposals, semester, partner){
if (!proposals.proposals){ return []}
Expand Down Expand Up @@ -264,7 +265,10 @@ export function queryProposals(semester, partner){
`
return graphqlClient().post('/graphql', { query })
.then(
response => convertProposals(response.data.data, semester, partner)
response => {
const convertedProposals = convertProposals(response.data.data, semester, partner)
return removeRejectedProposals(convertedProposals)
}
)
}

Expand Down
7 changes: 4 additions & 3 deletions src/components/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ import { storePartnerAllocations } from '../actions/timeAllocationActions'
import { semestersArray, getPartnerList, getAstronomersList } from '../util/filters'
import { defaultSemester } from '../util'
import { ADMINISTRATOR, SALT_ASTRONOMER, BOARD, TAC_CHAIR } from '../types'
import fetchStatistics from '../actions/statisticsActions'
import {fetchStatistics, fetchPartnerStatistics} from '../actions/statisticsActions'

class Filters extends React.Component {
updateSemester = value => {
const { dispatch, filters } = this.props
dispatch(fetchProposals( value, filters.selectedPartner))
dispatch(fetchPartnerStatProposals( value, filters.selectedPartner))
dispatch(fetchStatistics( value, filters.selectedPartner))
dispatch(fetchStatistics(value, filters.selectedPartner))
dispatch(fetchPartnerStatistics(value, filters.selectedPartner))
dispatch(storePartnerAllocations(value, filters.selectedPartner))
dispatch(semesterChange(value))
};
updatePartner = value => {
const { dispatch, filters } = this.props
dispatch(fetchProposals( filters.selectedSemester, value))
dispatch(fetchPartnerStatProposals( filters.selectedPartnerStatsSemester, value))
dispatch(fetchStatistics(filters.selectedPartnerStatsSemester, value))
dispatch(fetchStatistics(filters.selectedSemester, value))
dispatch(fetchPartnerStatistics(filters.selectedPartnerStatsSemester, value))
dispatch(storePartnerAllocations(filters.selectedSemester, value))
dispatch(partnerChange(value))
};
Expand Down
13 changes: 13 additions & 0 deletions src/components/messages/NoRejectedProposalsMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'

const NoRejectedProposalsMessage = () => (
<div>
<div className='notification'>
<div>
<p>Please note that rejected proposals are not included.</p>
</div>
</div>
</div>
)

export default NoRejectedProposalsMessage
2 changes: 2 additions & 0 deletions src/components/pages/LiaisonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {downloadSummary, getLiaisonUsername} from '../../util'
import {reduceProposalsPerAstronomer} from '../../util/filters'
import {ADMINISTRATOR} from '../../types'
import {isLiaisonAstronomerUpdated} from '../../util/proposal-filtering'
import NoRejectedProposalsMessage from '../messages/NoRejectedProposalsMessage'

const requestSummary = (event, proposalCode, semester) => {

Expand All @@ -28,6 +29,7 @@ const LiaisonPage = ({proposals, filters, astronomers, user, setLiaison, initPro
const { username } = user
return (
<div>
<NoRejectedProposalsMessage />
<LiaisonTable
proposals={ filteredProposals }
initProposals={ initProposals }
Expand Down
4 changes: 3 additions & 1 deletion src/components/pages/PartnerStatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TransparencyDistributionHistogram from '../plots/TransparencyDistribution
import TransparencyDistributionTable from '../tables/statisticsTables/ObservingStatisticsTransparacy'
import TimeBreakdownDistribution from '../plots/TimeBreakdownDistribution'
import ObservingStatisticsTimeBreakdown from '../tables/statisticsTables/ObservingStatisticsTimeBreakdown'
import NoRejectedProposalsMessage from '../messages/NoRejectedProposalsMessage'

class PartnerStatPage extends React.Component {
// Updates the comment of the proposal's completeness
Expand Down Expand Up @@ -59,6 +60,7 @@ class PartnerStatPage extends React.Component {
const filteredProposals = proposals.filter(p => p.status !== 'DELETED' && p.status !== 'REJECTED')
return (
<div>
<NoRejectedProposalsMessage />
<p style={ {textAlign: 'left'} }>
<a target='_blank' href={ linkToDashboard }> Click here for navigating to the dashboard </a>
</p>
Expand Down Expand Up @@ -149,7 +151,7 @@ export default connect(store => (
user: store.user.user,
partnerShareTimes: store.partnerShareTimes.partnerShareTimes,
loading: store.partnerStatProposals.fetching,
statistics: store.statistics.statistics,
statistics: store.statistics.partnerStatistics,
submittingCompletionComment: store.partnerStatProposals.submittingCompletionComment,
submittedCompletionComment: store.partnerStatProposals.submittedCompletionComment,
submittingCommentError: store.partnerStatProposals.errors.submittingCommentError
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/StatisticsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import RSSDetectorModeTable from '../tables/statisticsTables/RSSDetectorModeTabl
import HRSStatistics from '../tables/statisticsTables/HRSStatistics'
import RSSObservingModeTable from '../tables/statisticsTables/RSSObservingModeTable'
import SALTICAMStatistics from '../tables/statisticsTables/SALTICAMStatistics'
import NoRejectedProposalsMessage from '../messages/NoRejectedProposalsMessage'

class StatisticsPage extends React.Component {

Expand Down Expand Up @@ -53,7 +54,7 @@ class StatisticsPage extends React.Component {

return(
<div>

<NoRejectedProposalsMessage />
<div className='stat-wrapper'>
<ProposalCountTable proposalStatistics={ proposalStatistics } />
<PartnerTimeTable proposals={ proposals } allocatedTime={ allocatedTime } partner={ partner } semester={ semester }/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/TechReviewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import TechReviewTable from '../tables/TechReviewTable'
import {defaultSemester, getLiaisonUsername} from '../../util'
import { reduceProposalsPerAstronomer } from '../../util/filters'
import NoRejectedProposalsMessage from '../messages/NoRejectedProposalsMessage'

class TechReviewPage extends React.Component {

Expand Down Expand Up @@ -47,8 +48,8 @@ class TechReviewPage extends React.Component {
}

return(

<div>
<NoRejectedProposalsMessage />
<TechReviewTable
user={ user }
proposals={ proposals }
Expand Down
12 changes: 7 additions & 5 deletions src/components/pages/TimeAllocationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { getPartnerList, listForDropdown } from '../../util/filters'
import { checkColumns, getIndexOfColumns, updateProposalFromCSV } from '../../util/uploadCsv'
import {updateTacComment, updateAllocatedTimePriority} from '../../actions/TimeAllocationsActions'
import { getTechnicalReport } from '../../util/technicalReports'
import NoRejectedProposalsMessage from '../messages/NoRejectedProposalsMessage'

class TimeAllocationPage extends React.Component {

Expand Down Expand Up @@ -174,6 +175,7 @@ class TimeAllocationPage extends React.Component {

return (
<div key={ partner } style={ {paddingBottom:'40px'} }>
<NoRejectedProposalsMessage />
<div className='stat-wrapper-center'>
<AvailableTimePerPartner
proposals={ partnerProposals[ partner ] || [] }
Expand Down Expand Up @@ -224,6 +226,11 @@ class TimeAllocationPage extends React.Component {
onClick={ () => downloadSummaries(partnerProposals[ partner ] || [], semester, partner) }>
Download summary files
</button>
{ // eslint-disable-next-line
submittedTimeAllocations.partner !== partner ? <div />
: submittedTimeAllocations.results ? <div style={ {color: '#60FF60', fontSize: '20px'} }>Successfully Submitted</div>
: <div style={ { color: '#FF6060', 'fontSize': '20px' } }>Fail to submit time allocations</div>
}
{
canSubmitForPartner &&
<button
Expand All @@ -234,11 +241,6 @@ class TimeAllocationPage extends React.Component {
</button>
}
</div>
{ // eslint-disable-next-line
submittedTimeAllocations.partner !== partner ? <div />
: submittedTimeAllocations.results ? <div style={ {color: '#60FF60', fontSize: '20px'} }>Successfully Submitted</div>
: <div style={ { color: '#FF6060', 'fontSize': '20px' } }>Fail to submit time allocations</div>
}
</div>

</div>
Expand Down
14 changes: 9 additions & 5 deletions src/components/tables/ProposalsPerPartner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash'
import { illegalAllocation } from '../../util/allocation'
import { goodTime, badTime } from '../../types'
import { getTechnicalReport } from '../../util/technicalReports'
import {downloadSummary} from '../../util/index'
import { downloadSummary, NumberParser } from '../../util/index'

const TimeAllocationInput = ({onChange, proposal, priority, partner, name}) => {
const sty = illegalAllocation(proposal, priority, partner) ? badTime : goodTime
Expand Down Expand Up @@ -164,10 +164,14 @@ const ProposalsPerPartner = ({proposals, partner, tacCommentChange, allocatedTim
}
</td>
<td><div className='table-height width-100' >{
parseFloat(p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p0 : 0 ) +
parseFloat(p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p1 : 0 ) +
parseFloat(p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p2 : 0 ) +
parseFloat(p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p3 : 0 )
new NumberParser(window.navigator.language)
.parse((p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p0 : 0 )) +
new NumberParser(window.navigator.language)
.parse((p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p1 : 0 )) +
new NumberParser(window.navigator.language)
.parse((p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p2 : 0 )) +
new NumberParser(window.navigator.language)
.parse((p.allocatedTime[ partner ] ? p.allocatedTime[ partner ].p3 : 0 ))
}</div></td>
<td>
{ canAllocate ?
Expand Down
36 changes: 35 additions & 1 deletion src/reducers/statistics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
FETCH_STATISTICS_START,
FETCH_STATISTICS_PASS,
FETCH_STATISTICS_FAIL
FETCH_STATISTICS_FAIL,
FETCH_PARTNER_STATISTICS_START,
FETCH_PARTNER_STATISTICS_PASS,
FETCH_PARTNER_STATISTICS_FAIL
} from '../types'

const initialState = {
Expand Down Expand Up @@ -46,6 +49,37 @@ export default function statistics (state = initialState, action = {}) {
statistics: action.payload.statistics
}
}
case FETCH_PARTNER_STATISTICS_START: {
return {
...state,
fetching: true,
fetched: false
}
}
case FETCH_PARTNER_STATISTICS_FAIL: {
return {
...state,
fetching: false,
fetched: false,
partnerStatistics: {},
errors: {
...state.errors,
fetchingError: action.payload.error
}
}
}
case FETCH_PARTNER_STATISTICS_PASS: {
return {
...state,
fetching: false,
fetched: true,
errors: {
...state.errors,
fetchingError: null
},
partnerStatistics: action.payload.partnerStatistics
}
}
default: {
return state
}
Expand Down
8 changes: 8 additions & 0 deletions src/styles/messages/messages.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@
color: #013d19;
padding: 2em 0 1em 0;
}

.notification {
text-align: center;
background: #cccccc;
font-size: 20px;
padding: 0.1em;
font-weight: bold;
}
7 changes: 4 additions & 3 deletions src/util/allocation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isFloat } from '../util'
import { isFloat, NumberParser } from '../util'

export function illegalAllocation(proposal, priority, partner) {
const t = proposal.allocatedTime[ partner ] ? proposal.allocatedTime[ partner ][ priority ] : 0
return !isFloat(t) || parseFloat(t) < 0
return !isFloat(t) || new NumberParser(window.navigator.language).parse(t) < 0
}

export function checkAllocatedTimes(proposals, partner){
Expand Down Expand Up @@ -35,7 +35,8 @@ export function getQuaryToAddAllocation(proposals, partner, semester){
`{
proposalCode: "${ p.proposalCode }",
priority: ${ t },
time: ${ p.allocatedTime[ partner ] ? p.allocatedTime[ partner ][ priority ] : 0 }
time: ${ p.allocatedTime[ partner ] ?
new NumberParser().parse(p.allocatedTime[ partner ][ priority ]) : 0 }
}`
)
})
Expand Down
Loading

0 comments on commit eaea7e4

Please sign in to comment.