Skip to content

Commit

Permalink
Merge pull request #63 from msramalho/dev
Browse files Browse the repository at this point in the history
v3.1.2
  • Loading branch information
msramalho committed Aug 11, 2019
2 parents d3e4a79 + ec104c2 commit a881f2e
Show file tree
Hide file tree
Showing 12 changed files with 488 additions and 237 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ After developing a new extractor, it should be added to the [options.html](optio
<!-- same for tests and <script></script> -->

### Tests
Testing a browser extension is hard. Nonetheless, we try. Tests are located in the [tests](tests/) folder and we use [mocha](https://mochajs.org/) and [chai](https://www.chaijs.com/) along with some [improvised magic](tests/setup.js).
Testing a browser extension is hard. Nonetheless, we try. Tests are located in the [test](test/) folder and we use [mocha](https://mochajs.org/) and [chai](https://www.chaijs.com/) along with some [improvised magic](tests/setup.js).

To run tests open the [tests.html](tests.html) file on the browser, this was the only way as chrome extensions cannot be fully developed as ES6 modules, as of now. This system works fairly well.
To run tests open the [tests.html](tests.html) file on the browser (we advise [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) for VSCode), this was the only way as chrome extensions cannot be fully developed as ES6 modules, as of now. This system works fairly well.

To create a new test, check the previous ones. If you need to load html as the current jquery context (you will for evey test with jquery selectors) you can do:
To create a new test, check the previous ones. If you need to load html as the current jquery context (you will for every test with jquery selectors) you can do:
```javascript
describe('what the test is about', function() {
it('should return some results', function(done) {
Expand Down Expand Up @@ -295,6 +295,12 @@ Credits to [Paomedia](https://www.iconfinder.com/icons/285665/calendar_icon) for
- Mozilla problem with minified files
- V3.1
- Minimalist changelog page
- fixed `exclude_urls_csv` bug that disabled all extractors
- updates to satisfy Firefox's restrictions
- Fixed `exclude_urls_csv` bug that disabled all extractors
- Updates to satisfy Firefox's restrictions
- V3.1.1
- Closed issues [#52](https://github.com/msramalho/SigTools/issues/52), [#45](https://github.com/msramalho/SigTools/issues/45)
- V3.1.2
- Fixed Broken Grades [#62](https://github.com/msramalho/SigTools/issues/62)
- Fixed Bad Exam Acronym parsing [#59](https://github.com/msramalho/SigTools/issues/59)
- Handled Firefox Add-ons problems with 3rd party libraries...
9 changes: 4 additions & 5 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link href="css/changelog.css" rel="stylesheet">

<script src="js/lib/jquery.min.js"></script>
<script src="js/lib/jquery-3.4.1.js"></script>
<script src="js/lib/bootstrap.min.js"></script>

<title>SigTools Changelog</title>
Expand All @@ -29,10 +29,9 @@ <h6>We are going minimalist. </h6>
<br>
<br>
<ul>
<li>Firefox Addons may be working, they are quite annoying about including external scripts</li>
<li>Fixed a bug in the <code>exclude_urls_csv</code> option that hid all extractors</li>
<li>Refactored this page to be simpler</li>
<li>The team wishes you good luck for the 2<sup>nd</sup> semester 馃挭</li>
<li>Fixed Broken Grades <a href="https://github.com/msramalho/SigTools/issues/62">#62</a></li>
<li>Fixed Bad Exam Acronym parsing <a href="https://github.com/msramalho/SigTools/issues/59">#59</a></li>
<li>Handled Firefox Add-ons problems with 3rd party libraries...</li>
</ul>
</div>
</main>
Expand Down
15 changes: 9 additions & 6 deletions js/extractors/bills.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Bill extends Extractor {
}],
textarea: [{
name: "description",
default: "Due: ${date}\nAmount: ${amount}"
default: "Amount: ${amount}"
}]
}
}
Expand Down Expand Up @@ -56,14 +56,17 @@ class Bill extends Extractor {
}

_parsePendingBill(billEl) {
let startDate = Bill._getDateOrUndefined($(billEl).children(':nth(3)').text())
let endDate = Bill._getDateOrUndefined($(billEl).children(':nth(4)').text())
let getDateFromBill = function(index){
let dateFromBill = Bill._getDateOrUndefined($(billEl).children(`:nth(${index})`).text());
if(dateFromBill === undefined) dateFromBill = new Date();
return dateFromBill;
}
return {
description: $(billEl).children(':nth(2)').text(),
amount: $(billEl).children(':nth(7)').text(),
from: startDate,
to: endDate,
date: endDate,
from: getDateFromBill(3),
to: getDateFromBill(4),
date: getDateFromBill(4),
location: "",
download: false
};
Expand Down
4 changes: 2 additions & 2 deletions js/extractors/exams.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Exams extends Extractor {
if (this.table) {
this.table.each((index, table) => {
table = $(table);
this.exams[index] = this.exams[index] == undefined ? this.getEvents(index) : this.exams[index];
this.exams[index] = this.exams[index] == undefined ? this.getEvents(index) : this.exams[index];
if (this.exams[index].events.length != 0) {
let saveBtn = $(`<a class="calendarBtn" title="Save exams to your Calendar"><img src="${chrome.extension.getURL("icons/calendar.svg")}"/></a>`);
table.before(saveBtn);
Expand Down Expand Up @@ -86,7 +86,7 @@ class Exams extends Extractor {
let end = new Date(day.getTime());
end = end.setHoursMinutes(hours, 1);
//get other variables from the html
let subjectInfo = exameTd.find("a:first-child()");
let subjectInfo = exameTd.find(">a:first-child()");
return {
from: start,
to: end,
Expand Down
58 changes: 32 additions & 26 deletions js/extractors/grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Grades extends Extractor {

constructor() {
super();
this.originalTable = $("table.dadossz");
this.originalTable = $(this.selector = "table.dadossz");
this.table = this.originalTable.clone();
this.ready();
}
Expand All @@ -29,26 +29,24 @@ class Grades extends Extractor {


attachIfPossible() {
let callback = removeDatatableIfExists(this.selector)

// return if table not found or not applied
if (!this.originalTable.length) return

// create div for attaching modules
// this.originalTable.before(`<div><div style="float:left;"></div><div style="float:right"></div></div>`)
this.originalTable.before(`<div class="gradeChartDiv" style="min-width: ${this.chart_min_width};"><h2 class="noBorder" style="margin-top:0;">SigTools Grade Analysis</h2></div>`)
// attach modules (order of invocation matters)
this.attachCharts()
this.attachMetrics()

// inject dynamic tables
this.originalTable.prev().after($(`<h2 class="noBorder">SigTools Dynamic Tables</h2>`))
this.originalTable.prepend($(`<thead>${this.originalTable.find("tr").html()}</thead>`))
this.originalTable.find("tbody tr:has(> th)").remove()
// sorting guide: https://www.datatables.net/plug-ins/sorting/
// $("table.dadossz").dataTable({
// paging: false,
// order: [],
// dom: 'Bfrtip',
// buttons: ['copy', 'csv', 'excel', 'print'],
// });
// inject data-tables
callback($(this.selector))
$("#DataTables_Table_0_wrapper").css({ //force the datable to be side-by-side with statistics
clear: "none",
display: "table"
})
}

/**
Expand Down Expand Up @@ -79,31 +77,39 @@ class Grades extends Extractor {
let g = this.getNumericGrades();
let m = math

let name = $(".nomelogin").html()
let mine = this.grades.find(i => i.name == name).grade
mine = $.isNumeric(mine) ? parseInt(mine) : 0
let mine = false
try {
// will fail if student is not in grades page
let name = $("a.nomelogin").text()
let nameRegex = name.split(" ").join(".*")
mine = this.grades.find(i => new RegExp(nameRegex).test(i.name)).grade
mine = $.isNumeric(mine) ? parseInt(mine) : 0
} catch {}

let passed = g.filter(x => x >= 10).length
let failed = this.getGrades().length - passed

let max = m.max(g),
min = m.min(g)
let max = m.max(g)
let best = this.grades.filter(i => i.grade == max).sort((a, b) => a - b)
let fail = this.grades.filter(i => !$.isNumeric(i.grade) || parseInt(i.grade) < 10).map(s => {
s.name = `${s.name} (${s.grade})`;
return s;
})

let metricsHtml = `
<div class="gradeMetrics">
<h4>Personal Analysis</h4>
<table>
<tr><td>My grade: </td><td>${mine}</td></tr>
<tr><td>Position: </td><td>${g.sort((a, b) => b - a).indexOf(mine)+1}潞</td></tr>
<tr><td>Same as me: </td><td>${this.getGrades().filter(i => i == mine).length}</td></tr>
</table>
<hr/>
<h4>Overall Statistics</h4>
<div class="gradeMetrics">`
if (mine != false) {
metricsHtml +=
`<h4>Personal Analysis</h4>
<table>
<tr><td>My grade: </td><td>${mine}</td></tr>
<tr><td>Position: </td><td>${g.sort((a, b) => b - a).indexOf(mine)+1}潞</td></tr>
<tr><td>Same as me: </td><td>${this.getGrades().filter(i => i == mine).length}</td></tr>
</table>
<hr/>`
}
metricsHtml +=
`<h4>Overall Statistics</h4>
<table>
<tr><td>Average: </td><td>${m.round(m.mean(g), 2)}</td> <td>Std: </td><td>${m.round(m.std(g),2)}</td></tr>
<tr><td>Min: </td><td>${m.min(g)}</td> <td>Max: </td><td>${m.max(g)}</td></tr>
Expand Down

0 comments on commit a881f2e

Please sign in to comment.