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

Feat add recap view for pomodoro extention #11944

Merged
merged 7 commits into from
May 3, 2024

Conversation

cchalop1
Copy link
Contributor

Description

I have had a recap page for pomodoro extention.

The goal is to have a page for resume all the data from the your previous pomodoro cycle.

I have had 3 informations:

  • number of cycle completed
  • number of time (in minutes) completed
  • numbers of back to back (cycles with less than 5 min between tow)

I thinks we can add more informations in futures but we can make a other PR for that.

fix #11054

Screencast

Screenshot 2024-04-23 at 10 11 27

Checklist

feat: add detail page to display the count of timer cycles
@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: pomodoro Issues related to the pomodoro extension labels Apr 23, 2024
@raycastbot
Copy link
Collaborator

raycastbot commented Apr 23, 2024

Thank you for your contribution! 🎉

🔔 @KELiON @pernielsentikaer @brodelp @susonthapa @mikikiv @MartinGonzalez @Nathanjms you might want to have a look.

@raycastbot raycastbot added the OP is contributor The OP of the PR is a contributor of the extension label Apr 23, 2024
@pernielsentikaer
Copy link
Collaborator

Hi @cchalop1 👋

It looks good to me, @KELiON do you mind checking this?

@pernielsentikaer pernielsentikaer self-assigned this Apr 23, 2024
@cchalop1
Copy link
Contributor Author

cchalop1 commented Apr 23, 2024

Thanks for the typo ! @pernielsentikaer

Comment on lines 18 to 28
function countTotalFocusTime(intervals: Interval[]) {
let total = 0;
for (const interval of intervals) {
for (const part of interval.parts) {
if (part.endAt) {
total += interval.length;
}
}
}
return total;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be filtered to only count interval.type === "focus"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you help here @cchalop1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right. I'm going to fix it.

Copy link
Contributor Author

@cchalop1 cchalop1 Apr 30, 2024

Choose a reason for hiding this comment

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

It is ok for you @mikikiv ?

@cchalop1 cchalop1 requested a review from mikikiv April 30, 2024 07:56
@pernielsentikaer
Copy link
Collaborator

Just waiting for @KELiON do check it now 🙂

@pernielsentikaer
Copy link
Collaborator

I haven't tested it well yet, but we can maybe optimize stats-pomodoro-timer.tsx but using something like this which will:

  • Avoid unnecessary iterations
  • Use more descriptive variable names
  • Use map, reduce, filter functions
import { usePromise } from "@raycast/utils";
import { getIntervalHistory } from "../lib/intervals";
import { Detail } from "@raycast/api";
import { Interval } from "../lib/types";

function calculateStats(intervals: Interval[]) {
  let completedCycles = 0;
  let totalFocusTime = 0;
  let backToBackCycles = 0;
  let prevEndAt = null;

  for (const interval of intervals) {
    for (const part of interval.parts) {
      if (part.endAt) {
        completedCycles++;
        totalFocusTime += interval.length;

        if (prevEndAt && part.startedAt - prevEndAt < 5 * 60 + 10) {
          backToBackCycles++;
        }

        prevEndAt = part.endAt;
      }
    }
  }

  return { completedCycles, totalFocusTime, backToBackCycles };
}

export default function StatsPomodoro() {
  const { data, isLoading } = usePromise(getIntervalHistory);
  const focusIntervals = data?.filter((interval) => interval.type === "focus") || [];

  const { completedCycles, totalFocusTime, backToBackCycles } = calculateStats(focusIntervals);

  const markdown = `# 🍅 Pomodoro Recap 🍅\n
  > 📊 Statistics of your pomodoro timer - all from the begin\n
   - You have completed **${completedCycles}** pomodoro cicle${completedCycles > 1 ? "s" : ""}. ✨\n
   - Total of **${totalFocusTime / 60}m** of focus time. ⏱️\n
   - Top Number of back to back pomodoro cicle${backToBackCycles > 1 ? "s" : ""}: **${backToBackCycles}**. 👑\n
    `;

  return <Detail isLoading={isLoading} markdown={markdown} />;
}

@cchalop1
Copy link
Contributor Author

cchalop1 commented May 2, 2024

I haven't tested it well yet, but we can maybe optimize stats-pomodoro-timer.tsx but using something like this which will:

  • Avoid unnecessary iterations
  • Use more descriptive variable names
  • Use map, reduce, filter functions
import { usePromise } from "@raycast/utils";
import { getIntervalHistory } from "../lib/intervals";
import { Detail } from "@raycast/api";
import { Interval } from "../lib/types";

function calculateStats(intervals: Interval[]) {
  let completedCycles = 0;
  let totalFocusTime = 0;
  let backToBackCycles = 0;
  let prevEndAt = null;

  for (const interval of intervals) {
    for (const part of interval.parts) {
      if (part.endAt) {
        completedCycles++;
        totalFocusTime += interval.length;

        if (prevEndAt && part.startedAt - prevEndAt < 5 * 60 + 10) {
          backToBackCycles++;
        }

        prevEndAt = part.endAt;
      }
    }
  }

  return { completedCycles, totalFocusTime, backToBackCycles };
}

export default function StatsPomodoro() {
  const { data, isLoading } = usePromise(getIntervalHistory);
  const focusIntervals = data?.filter((interval) => interval.type === "focus") || [];

  const { completedCycles, totalFocusTime, backToBackCycles } = calculateStats(focusIntervals);

  const markdown = `# 🍅 Pomodoro Recap 🍅\n
  > 📊 Statistics of your pomodoro timer - all from the begin\n
   - You have completed **${completedCycles}** pomodoro cicle${completedCycles > 1 ? "s" : ""}. ✨\n
   - Total of **${totalFocusTime / 60}m** of focus time. ⏱️\n
   - Top Number of back to back pomodoro cicle${backToBackCycles > 1 ? "s" : ""}: **${backToBackCycles}**. 👑\n
    `;

  return <Detail isLoading={isLoading} markdown={markdown} />;
}

Yes I agree with you, it is clearer if we put everything in the calculatesStats function. I push for change

@pernielsentikaer
Copy link
Collaborator

I hope I didn't break something since I didn't have any data to test with 🙂 Is this ready for another review?

@cchalop1
Copy link
Contributor Author

cchalop1 commented May 2, 2024

I have tested with my local data and i work well. Yep it is ready !

Copy link
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

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

Hi 👋

Looks good to me, approved 🔥

@raycastbot raycastbot merged commit 37d1c88 into raycast:main May 3, 2024
6 checks passed
Copy link
Contributor

github-actions bot commented May 3, 2024

Published to the Raycast Store:
https://raycast.com/asubbotin/pomodoro

@raycastbot
Copy link
Collaborator

🎉 🎉 🎉

Such a great contribution deserves a reward, but unfortunately we couldn't find your Raycast account based on your GitHub username (@cchalop1).
Please link your GitHub account to your Raycast account to receive your credits and soon be able to exchange them for some swag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension fix / improvement Label for PRs with extension's fix improvements extension: pomodoro Issues related to the pomodoro extension OP is contributor The OP of the PR is a contributor of the extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stats for Pomodoro
4 participants