Skip to content

Commit

Permalink
Fix queries
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Mar 24, 2023
1 parent 6bd21be commit 1544324
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
29 changes: 17 additions & 12 deletions cache.js
Expand Up @@ -39,15 +39,6 @@ const INCOME_CONDITION = `length(code) = 10 AND year = ` + (YEAR - 1) + `
AND code LIKE '0000%%'
AND NOT ` + DEFICIT_FUNDING_CONDITION;

const SQL_TOTAL_PROPOSAL_DATA = `
SELECT sum(net_allocated) AS total_amount
FROM raw_budget
WHERE length(code) = 8 and year = ` + PROPOSAL_YEAR + TOTAL_BUDGET_CONDITION;
const SQL_TOTAL_PREV_PROPOSAL_DATA = `
SELECT sum(net_allocated) AS total_amount
FROM raw_budget
WHERE length(code) = 8 and year = ` + (PROPOSAL_YEAR-1) + TOTAL_BUDGET_CONDITION;

const SQL_FUNC_BUBBLES_DATA = `
SELECT
func_cls_title_1->>0 || ':budget/C' || ((func_cls_json->>0)::json->>0) || '/' || '` + YEAR + `' AS bubble_group,
Expand Down Expand Up @@ -118,6 +109,13 @@ function sleep(ms) {
})
}

function sql_total_amount(year) {
const SQL = `
SELECT sum(net_allocated) AS total_amount
FROM raw_budget
WHERE length(code) = 8 and year = ` + year + TOTAL_BUDGET_CONDITION;
return fetch_sql(SQL).then(data => data[0].total_amount);
}

function cached_get_url(url) {
const filePath = 'build-cache/' + crypto.createHash('md5').update(url).digest('hex') + '.json';
Expand Down Expand Up @@ -239,7 +237,14 @@ function fetch_data(sql) {
function fetch_doc(doc) {
const url = DOC_URL + doc;
return cached_get_url(url)
.then((data => data.value));
.then((data => data.value))
.then((data => {
if (data.__redirect) {
return fetch_doc(data.__redirect);
} else {
return data;
}
}));
}

function deficitChart() {
Expand Down Expand Up @@ -309,8 +314,8 @@ function get_cache() {
deficitChart(),
educationBudgetChart(),
supportsChart(),
fetch_sql(SQL_TOTAL_PROPOSAL_DATA),
fetch_sql(SQL_TOTAL_PREV_PROPOSAL_DATA),
sql_total_amount(PROPOSAL_YEAR),
sql_total_amount(YEAR),
]).then((data) => {
ret = {
year: YEAR,
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Expand Up @@ -38,8 +38,8 @@ export class AppComponent implements OnInit {
this.funcCategories.forEach((category: any) => {
this.totalAmount += category.amount;
});
this.proposalAmount = bubbles.proposalAmount[0] && bubbles.proposalAmount[0].total_amount;
this.prevProposalAmount = bubbles.prevProposalAmount[0] && bubbles.prevProposalAmount[0].total_amount;
this.proposalAmount = bubbles.proposalAmount;
this.prevProposalAmount = bubbles.prevProposalAmount;
}

@HostListener('window:scroll', ['$event'])
Expand Down
Expand Up @@ -29,7 +29,7 @@ export class CategoryVisualizationComponent implements OnInit, AfterViewInit {
}

formatAmount(value: number): string {
return this.utils.formatNumber(value / 1000000000, 2) + __T('מיליארד') + ' ₪';
return this.utils.formatNumber(value / 1000000000, 2) + ' ' + __T('מיליארד') + ' ₪';
}

constructor(private utils: UtilsService) {}
Expand Down
4 changes: 2 additions & 2 deletions src/app/hero/hero.component.ts
Expand Up @@ -410,9 +410,9 @@ const dialog = [
Q(__('מה כדאי לי לעשות עכשיו?')),
A(__('להתחיל לחפור באתר כמובן 🤓')),
A(__('הנה כמה כיוונים מעניינים:')),
A('<a target="_blank" href="/s/?q=פעילות לעידוד עסקים קטנים ובינוניים&dd=supports">' +
/*A('<a target="_blank" href="/s/?q=פעילות לעידוד עסקים קטנים ובינוניים&dd=supports">' +
__('אילו סטארט-אפים מקבלים תמיכה מהמדען הראשי') +
'</a>?'),
'</a>?'),*/
A(__('כמה תקציבים מקבלת') +
'<a target="_blank" href="/i/org/municipality/500210315"> ' +
__('העיר שדרות') +
Expand Down

0 comments on commit 1544324

Please sign in to comment.