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

#2308: Add extra few days in SuccessRateLine if survey is still running #2338

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/js/components/charts/SuccessRateLine.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ export default class SuccessRateLine extends Component<Props> {
-1
)
const oneMonthFromStart = d3.timeMonth.offset(initialTime, 1)
lastTime = d3.max([d3.max(data.values, (d) => d.time), oneMonthFromStart])
const surveyLastDay = d3.max(data.values, (d) => d.time)
// Select lastTime to show as max x-axis value in the chart
//
// We want the chart to show at least 1 month.
// If the survey is still running and for more than one month already,
// we add some extra days to give the sense of incompleteness
const lastDay = data.isRunning ? d3.timeDay.offset(surveyLastDay, 5) : surveyLastDay
lastTime = d3.max([lastDay, oneMonthFromStart])
}

const x = d3.scaleTime().domain([initialTime, lastTime]).range([0, width])
Expand Down
11 changes: 8 additions & 3 deletions assets/js/components/surveys/SurveyShow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ class SurveyShow extends Component<any, State> {
}
}

surveyIsRunning(survey){
return survey && survey.state == "running"
}

showHistograms() {
const { survey } = this.props
return survey && survey.state == "running"
return this.surveyIsRunning(survey)
}

stopSurvey() {
Expand Down Expand Up @@ -201,7 +205,7 @@ class SurveyShow extends Component<any, State> {

let stopComponent = null
let switchComponent = null
if (!readOnly && survey.state == "running") {
if (!readOnly && this.surveyIsRunning(survey)) {
if (project.level == "owner" || project.level == "admin") {
let lockOpenClass, lockClass
if (survey.locked) {
Expand Down Expand Up @@ -303,6 +307,7 @@ class SurveyShow extends Component<any, State> {
label: "Success rate",
color: "#000000",
id: "successRate",
isRunning: this.surveyIsRunning(survey),
values: percentages.successRate.map((v) => ({
time: new Date(v.date),
value: Number(v.percent),
Expand All @@ -311,7 +316,7 @@ class SurveyShow extends Component<any, State> {


forecasts = forecasts.map((d) => {
if (this.shouldForecast(d, 100, survey.state == "running")) {
if (this.shouldForecast(d, 100, this.surveyIsRunning(survey))) {
return {
...d,
forecast: this.getForecast(d.values[0], d.values[d.values.length - 1], 100),
Expand Down