Skip to content

Commit

Permalink
add export to sheets feature
Browse files Browse the repository at this point in the history
Signed-off-by: Anvay Mathur <contact@anvaymathur.com>
  • Loading branch information
megagames-me committed Dec 31, 2024
1 parent 2a207e6 commit f414d45
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 15 deletions.
41 changes: 32 additions & 9 deletions src/content_script/scores/ScoreTools.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { Tools } from ".";
import type { GradeManager } from "../../models/grades";
import Export from "./scoreTools/Export.svelte";
import SingleAssignment from "./scoreTools/SingleAssignment.svelte";
let curTool: Tools = Tools.CATEGORY_WEIGHTING;
Expand All @@ -20,15 +21,35 @@
>
<div>
<h1 class="tw-pb-2 tw-text-2xl">Tools</h1>
<select
bind:value={curTool}
class="tw-rounded-md tw-border-[#CCCCCC] tw-border-solid tw-border tw-p-1"
>
<option value={Tools.CATEGORY_WEIGHTING}
>Category Weighting and Advanced See All Possibilities</option
>
<option value={Tools.NONE}>None</option>
</select>
<div class="tw-flex tw-flex-col tw-gap-1">
<label>
<input
type="radio"
value={Tools.CATEGORY_WEIGHTING}
bind:group={curTool}
name="pestool"
/>
Category Weighting and Advanced See All Possibilities
</label>
<label>
<input
type="radio"
value={Tools.EXPORT}
bind:group={curTool}
name="pestool"
/>
Export Customizable Grades
</label>
<label>
<input
type="radio"
value={Tools.NONE}
bind:group={curTool}
name="pestool"
/>
None
</label>
</div>
</div>

{#if curTool == Tools.CATEGORY_WEIGHTING}
Expand All @@ -37,6 +58,8 @@
{gradeManager}
leftOverEntries={leftOverE}
/>
{:else if curTool == Tools.EXPORT}
<Export {gradeManager} {finalPercent} />
{/if}
<p>
<span class="tw-font-bold"
Expand Down
1 change: 1 addition & 0 deletions src/content_script/scores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { getFinalPercent } from "./scoresUtilities";

export enum Tools {
CATEGORY_WEIGHTING = "CATEGORY_WEIGHTING",
EXPORT = "EXPORT",
NONE = "NONE"
}

Expand Down
73 changes: 73 additions & 0 deletions src/content_script/scores/scoreTools/Export.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script lang="ts">
import {
formattedGrade,
getDisplayGradePercent,
type GradeManager,
} from "../../../models/grades";
export let finalPercent: number;
export let gradeManager: GradeManager;
console.log(finalPercent, gradeManager);
const exportGrades = async () => {
try {
let str = `Official Final Percent:\t${finalPercent}%\n\n`;
str += `Category name\tAssignment name\tGrade\tAssignment weight\tWeight in category\tWeight in final grade\tExempt?\n`;
for (const category of gradeManager.categories) {
str += `${category.name} (${category.weight}%)\t`;
let assignments =
gradeManager.getAssignmentsByCategoryEntries(category);
for (const [assignment, idx] of assignments) {
str += `${assignment.name}\t${formattedGrade(
assignment.grade,
)} ${getDisplayGradePercent(assignment.grade)}\t${
assignment.weight
}\t${
assignment.exempt
? ""
: gradeManager.getEffectiveRelativeWeight(idx)
}\t${
assignment.exempt ? "" : gradeManager.getEffectiveWeightInTotal(idx)
}\t${assignment.exempt ? "Yes" : "No"}\n\t`;
}
str += "\n";
}
await navigator.clipboard.writeText(str);
alert(
"Grades data copied to clipboard! Read below the button you just clicked for what to do next.",
);
} catch (error) {
console.error("Failed to copy grades data to clipboard:", error);
alert("Failed to copy grades data to clipboard. Try again.");
}
};
</script>

<div>
<h1 class="!tw-mb-2 !tw-mt-3">Export Customizable Grades</h1>
<p>
This tool allows you to export your grades to a Google Spreadsheet,
containing all the weightings for assignments and categories.<b
>All the data comes from the "Category Weighting and Advanced See All
Possibilities" tool.</b
> So, you can modify the category weightings and assignments. This tool is built
for final exam week when PowerSchool is closed so you can remember your grades.
This will exist until I feel like creating an in-extension solution to storing
your data.
</p>
<button on:click={exportGrades}>Copy spreadsheet data to clipboard</button>
<p>
Once you've clicked the above button, go to the Google Sheet of your choice
or <a href="https://sheets.new" target="_blank"
>use this link to create a new one</a
>. Then, just paste (Cmd-V or Ctrl-V) into the top-left cell in the sheet.
You may have to resize the spreadsheet columns for the text to be visible.
Now, you can do whatever you want. I would suggest having one Google
Spreadsheets file with multiple tabs for each class. You can create new tabs
by looking at the bottom left hand corner of the screen and clicking on the
+ sign to add a tab (also known, confusingly, as a "sheet") to the existing
spreadsheet.
</p>
</div>
10 changes: 4 additions & 6 deletions src/content_script/scores/scoreTools/SingleAssignment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Category,
convertPercentCutoffToGrade,
formattedGrade,
getDisplayGradePercent,
GradeManager,
gradeToPercent,
listOfGrades,
Expand Down Expand Up @@ -148,12 +149,6 @@
};
}
function getDisplayGradePercent(grade: Grade) {
if (!grade.startsWith("INC")) return `(${gradeToPercent[grade]}%)`;
if (grade == "INC_NO_CLASS_CREDIT") return `(No Class Credit)`;
return `(0%)`;
}
function onGradeChange(e: Event, i: number) {
const target = e.target as HTMLSelectElement;
if (target.value == "see") {
Expand Down Expand Up @@ -524,6 +519,9 @@

<div>
{#if gradeManager.categories.length > 0}
<h1 class="!tw-mb-2 !tw-mt-3">
Category Weighting and Advanced See All Possibilities
</h1>
<!-- CATEGORY WEIGHTING -->
<button id="helpBtn" class="!tw-ml-0"
>Tutorial (click to start guided tour and interactive explanation) <b
Expand Down
11 changes: 11 additions & 0 deletions src/models/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export const formattedGrade = (grade: Grade) => {
return grade;
}

export function getDisplayGradePercent(grade: Grade) {
if (!grade.startsWith("INC")) return `(${gradeToPercent[grade]}%)`;
if (grade == "INC_NO_CLASS_CREDIT") return `(No Class Credit)`;
return `(0%)`;
}

// Function to return gcd of a and b
function gcd(a: number, b: number): number {
if (a == 0)
Expand Down Expand Up @@ -166,6 +172,11 @@ export class GradeManager {
return this.assignments.filter((assignment) => assignment.category === category && (includeExempt || !assignment.exempt));
}

/**
*
* @param category the category to get the assignments from
* @returns an array of [Assignment, number] entries where the number is the index of the assignment in the assignments array
*/
public getAssignmentsByCategoryEntries(category: Category): [Assignment, number][] {
return (this.assignments.map((a, i) => [a, i]) as [Assignment, number][]).filter((assignmentEntry) => assignmentEntry[0].category === category);
}
Expand Down

0 comments on commit f414d45

Please sign in to comment.