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

display the total daily gaps percantage #57

Merged
merged 8 commits into from
Oct 6, 2023

Conversation

ArkadiK94
Copy link
Collaborator

Displaying the total daily gaps percentage in the "gaps" page

@ShayAdler @NoamGaash

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help!
here are a few comments,
I believe implementing those suggestions could increase code quality, but let me know what you're thinking

switch (true) {
case gapsPrecentage === 0:
return (
<TitleCellPrecentage style={{ color: '#097d09' }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colors can be moved to constants to improve readability and consistency

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I can also add css classes for these colors, so we could use them in other elements if needed. Name of the classes: "great-result" (for green), "average-result" (for yellow), "terrible-result" (for red)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even better!

.then(setGaps)
.then((gaps) => {
setGaps(gaps)
const ridesInTime = gaps?.filter((gap) => formatStatus([], gap) === TEXTS.ride_as_planned)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the formatting separated from logic. In the future, the formatting function may wrap the text and apply various modifications, so we probably don't want it to be coupled with this filter


const GapsPage = () => {
const { search, setSearch } = useContext(SearchContext)
const { operatorId, lineNumber, timestamp, routes, routeKey } = search
const [gaps, setGaps] = useState<GapsList>()
const [gapsPrecentage, setGapsPrecentage] = useState<number>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please try to keep as few state variables as possible

src/pages/GapsPage.tsx Outdated Show resolved Hide resolved
Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help!
here are a few comments,
I believe implementing those suggestions could increase code quality, but let me know what you're thinking

@ArkadiK94
Copy link
Collaborator Author

@NoamGaash I implemented the suggestions. Please, review them again.

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, it looks great,
but I think we should reconsider the hard-coded thresholds in you files
what do you think?

src/pages/components/DisplayGapsPercentage.tsx Outdated Show resolved Hide resolved
Comment on lines 7 to 9
$great-result: #097d09;
$average-result: #b4b407;
$terrible-result: #b90a0a;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love these namings!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment on lines 8 to 19
let status = ''
switch (true) {
case gapsPrecentage === 0:
status = 'great'
break
case gapsPrecentage < 20:
status = 'average'
break
case gapsPrecentage >= 20:
status = 'terrible'
break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about the numbers?
if the gap percentage is 1/10,000, will you consider it "average"?
also, let's try something cleaner
for example -

const statuses = [
    {
        min: -Infinity,
        status: "invalid"
    },
    {
        min: 0,
        status: "great"
    },
    {
        min: 10,
        status: "average"
    },
    {
        min: 20,
        status: "terrible"
    },
    {
        min: 101,
        status: "invalid"
    },
]

function getStatus(percentage) {
    return statuses.findLast(status => status.min < percentage).status
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also relates to my coloring method in the new "gaps patterns page", and I think we should be consistent with our coloring \ terms. So maybe, even something like that could be better and used by both pages:

 const statuses = [
    {
        min: -Infinity,
        status: "invalid"
    },
    {
        min: 0,
        status: "great",
        color: "green" // or a more specific color code
    },
    {
        min: 10,
        status: "average",
        color: "orange"
    },
    {
        min: 20,
        status: "terrible",
        color: "red"
    },
    {
        min: 101,
        status: "invalid"
    },
]

Copy link
Collaborator Author

@ArkadiK94 ArkadiK94 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShayAdler I didn't understand to which page you are referring to because my changes are for the GapsPage as well.

The 'status' variable is for choosing one of these classes

&-great-result {
    color: $great-result;
}
&-average-result {
    color: $average-result;
}
&-terrible-result {
    color: $terrible-result;
}

the variables (in scss file) contain

$great-result: #097d09;
$average-result: #b4b407;
$terrible-result: #b90a0a;

Did you mean to change the colors in the variables? as follows:

$great-result:  green;
$average-result: orange;
$terrible-result: red;

Copy link
Collaborator Author

@ArkadiK94 ArkadiK94 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NoamGaash

if the gap percentage is 1/10,000, will you consider it "average"?

Yes, the green is for TEXTS.all_rides_completed
the average is for missing some rides
and the red is for missing more than 20% of rides.
Make sense and this is also the requirements from the issue

green - "כל הנסיעות בוצעו"
yellow - < 20% miss
red - >20%miss

It make sense because even if one bus will not make the ride as scheduled it can have some bad consequences on a group of people. They can late for work , for a meeting , take their child from school. So yeah, we count on the buses to take us to important places. When one bus will not make it on time we will need to wait another half an hour for the next bus (in some cities)

I prefer your cleaner code. Do you want me to make the boundaries configurable as well? I refer to the 10%,20% ?

I thought about this, and maybe the "average-result" keyword is confusing here. I think to change it to "decent-result". Hmm, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, you're right

@ArkadiK94
Copy link
Collaborator Author

@NoamGaash @ShayAdler Hi, could you answer to my questions about the comments so I will make the right modifications?

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with comments
thank you for your help!!!

src/pages/GapsPage.tsx Outdated Show resolved Hide resolved
Comment on lines 8 to 19
let status = ''
switch (true) {
case gapsPrecentage === 0:
status = 'great'
break
case gapsPrecentage < 20:
status = 'average'
break
case gapsPrecentage >= 20:
status = 'terrible'
break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, you're right

@ArkadiK94
Copy link
Collaborator Author

I changed the code. To use the findLast() method of an array I had to update the typescript version. @NoamGaash

@NoamGaash NoamGaash enabled auto-merge (squash) October 4, 2023 20:25
@NoamGaash
Copy link
Member

do you need help with the conflicts?

@ArkadiK94
Copy link
Collaborator Author

image
There is some error, it is not related to my changes... Do you want me to open an issue about it?

@NoamGaash
Copy link
Member

NoamGaash commented Oct 5, 2023

@ArkadiK94
try to run git pull and yarn

@ArkadiK94
Copy link
Collaborator Author

Great, thanks , the error is not shown. Could you merge this pr?

@NoamGaash NoamGaash merged commit 046ce74 into hasadna:main Oct 6, 2023
4 checks passed
@NoamGaash
Copy link
Member

Sure! thank you!

@aviv1620
Copy link
Collaborator

aviv1620 commented Oct 6, 2023

you change the typescript version in package.json but not in yarn.lock.
So every time I or someone runs yarn install the file changes.
Can you run yarn install and then commit push and merge again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants