Skip to content

Commit

Permalink
Implement new suggestions in inform
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasatisocco committed Aug 10, 2023
1 parent d02c77b commit e565bb8
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 15 deletions.
22 changes: 11 additions & 11 deletions .firebase/hosting.YnVpbGQvd2Vi.cache
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ canvaskit/skwasm.worker.js,1689174938000,125427ebed610a77eee828e2eacc3567c6d5e60
canvaskit/chromium/canvaskit.js,1689174868000,10ec5a22cd3c3cff50d3205798dbc1cb2a223691b6654c64443344c5742ca1ad
canvaskit/chromium/canvaskit.wasm,1689174862000,4b0f2a5ee8d889f8dee6eab57395315ae160d267f67a80401df7f3a7f5725153
icons/favicon.ico,1684768745320,aaeda556bea424bd5d9cbd4ca99e53187fe8f2a101e9b1c47b331136150c5075
index.html,1690325577090,41e0350c2d98873274b106d152a969460231482a2e03f2945ee44620e6bbe50b
version.json,1690325576245,18b2059e30616c58e72279b9cd0a4c3b8b8972a9a147b2106acfa0f4166765fe
flutter_service_worker.js,1690325577424,50c0477aba104ccd1668e9e14f1072d44574ada65c349bfb8894cfa6ad7e6c1d
assets/AssetManifest.bin,1690325576342,e87c242f556272301da5a2f63efda1aa90f784cf91010c89e130d6caccf902d6
assets/AssetManifest.json,1690325576342,94b91940b0f6105aa27633875ff12272cda9143a3e2656ea994647d7afc85714
assets/FontManifest.json,1690325576342,2a26cf55926df210ccb9d713372cb114e0a12bf97104f6833e382566e2e7b16e
assets/fonts/MaterialIcons-Regular.otf,1690325577087,ac80989e08c8850552ab3f7af95e15bc9a85b4dfb8d743955abb37135cb16c48
flutter.js,1690325555047,cc5bca0a2b8ec99223db7f9ab924b67cca075f0e4997f262749f06e34b5965ef
assets/shaders/ink_sparkle.frag,1690325576486,7e2c4d11b7e2f4b97e4af6c3d7a3618158b451971f430b4befae8ea6aa756131
assets/NOTICES,1690325576342,d7d539f78d4bd4a8280f98776a642decf3c737423552c9f8a9bc2919d64fd5eb
main.dart.js,1690325576031,5b983ce4a7d024e7e527679b58ef344b87f471b934051c6c1686da5615baebe2
index.html,1691708554959,f9a347538473206ead1bf406669d4969f7df4a04f0298de421e04c392d9d4ae9
assets/AssetManifest.bin,1691708554177,e87c242f556272301da5a2f63efda1aa90f784cf91010c89e130d6caccf902d6
version.json,1691708554055,18b2059e30616c58e72279b9cd0a4c3b8b8972a9a147b2106acfa0f4166765fe
assets/AssetManifest.json,1691708554177,94b91940b0f6105aa27633875ff12272cda9143a3e2656ea994647d7afc85714
flutter_service_worker.js,1691708555533,0f7f009e169efcece17f158055bdb15a1b1c5c1fb5d1e81430d4b8034f811142
flutter.js,1691708532416,cc5bca0a2b8ec99223db7f9ab924b67cca075f0e4997f262749f06e34b5965ef
assets/shaders/ink_sparkle.frag,1691708554333,7e2c4d11b7e2f4b97e4af6c3d7a3618158b451971f430b4befae8ea6aa756131
assets/FontManifest.json,1691708554177,2a26cf55926df210ccb9d713372cb114e0a12bf97104f6833e382566e2e7b16e
assets/fonts/MaterialIcons-Regular.otf,1691708554954,ac80989e08c8850552ab3f7af95e15bc9a85b4dfb8d743955abb37135cb16c48
assets/NOTICES,1691708554177,d7d539f78d4bd4a8280f98776a642decf3c737423552c9f8a9bc2919d64fd5eb
main.dart.js,1691708553461,ff476de3fe006654f4c7e1f11cece17b982122abab628b5ebf81ecb2d307ac9d
234 changes: 231 additions & 3 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,173 @@ async function addResultPDF(
functions.logger.log("Results page added to PDF");
}

/**
* This function adds the suggestions page to the pdf.
* @param {PDFDocument} pdfDoc The PDF document.
* @param {string[]} qualitySuggestions The path to the results.
* @param {string[]} businessSuggestions The path to the results.
* @param {string[]} wellnessSuggestions The path to the results.
* @param {string[]} communitySuggestions The path to the results.
*/
async function addSuggestionsPage(
pdfDoc: PDFDocument,
qualitySuggestions: string[],
businessSuggestions: string[],
wellnessSuggestions: string[],
communitySuggestions: string[],
) : Promise<void> {
const page = pdfDoc.insertPage(5);
const height = page.getSize().height;
const font = await pdfDoc.embedFont(StandardFonts.TimesRoman);
const boldFont = await pdfDoc.embedFont(StandardFonts.TimesRomanBoldItalic);
const fontSize = 12;
const lineHeight = 20;
let y = height - 100;
const title = "Las orientaciones por dominios";
page.drawText(
title,
{
x: 30,
y: y,
size: 16,
color: rgb(0, 0, 0),
font: boldFont,
}
);
y -= lineHeight * 2;
page.drawText(
"Calidad de servicio",
{
x: 50,
y: y,
size: 14,
color: rgb(0, 0, 0),
font: boldFont,
}
);
y -= lineHeight;
qualitySuggestions.forEach((suggestion) => {
page.drawText("• ", {
x: 70,
y,
size: fontSize,
color: rgb(0, 0, 0),
font,
});
page.drawText(
suggestion,
{
x: 85,
y: y,
size: fontSize,
color: rgb(0, 0, 0),
font: font,
}
);
y -= lineHeight;
});

y -= lineHeight;
page.drawText(
"Calidad de negocio",
{
x: 50,
y: y,
size: 14,
color: rgb(0, 0, 0),
font: boldFont,
}
);
y -= lineHeight;
businessSuggestions.forEach((suggestion) => {
page.drawText("• ", {
x: 70,
y,
size: fontSize,
color: rgb(0, 0, 0),
font,
});
page.drawText(
suggestion,
{
x: 85,
y: y,
size: fontSize,
color: rgb(0, 0, 0),
font: font,
}
);
y -= lineHeight;
});

y -= lineHeight;
page.drawText(
"Bienestar personal",
{
x: 50,
y: y,
size: 14,
color: rgb(0, 0, 0),
font: boldFont,
}
);
y -= lineHeight;
wellnessSuggestions.forEach((suggestion) => {
page.drawText("• ", {
x: 70,
y,
size: fontSize,
color: rgb(0, 0, 0),
font,
});
page.drawText(
suggestion,
{
x: 85,
y: y,
size: fontSize,
color: rgb(0, 0, 0),
font: font,
}
);
y -= lineHeight;
});

y -= lineHeight;
page.drawText(
"Aportes a la profesión",
{
x: 50,
y: y,
size: 14,
color: rgb(0, 0, 0),
font: boldFont,
}
);
y -= lineHeight;
communitySuggestions.forEach((suggestion) => {
page.drawText("• ", {
x: 70,
y,
size: fontSize,
color: rgb(0, 0, 0),
font,
});
page.drawText(
suggestion,
{
x: 85,
y: y,
size: fontSize,
color: rgb(0, 0, 0),
font: font,
}
);
y -= lineHeight;
});
functions.logger.log("Suggestions page added to PDF");
}

/**
* This function adds the guide to the pdf.
* @param {PDFDocument} pdfDoc The PDF document.
Expand Down Expand Up @@ -176,12 +343,20 @@ async function addGuidePDF(
* @param {string} guidePath The path to the guide.
* @param {string} userName The user name.
* @param {string} date The date of the test.
* @param {string[]} qualitySuggestions The quality suggestions.
* @param {string[]} businessSuggestions The business suggestions.
* @param {string[]} wellnessSuggestions The wellness suggestions.
* @param {string[]} communitySuggestions The community suggestions.
*/
async function createPDF(
resultsPath: string,
guidePath: string,
userName: string,
date: string,
qualitySuggestions: string[],
businessSuggestions: string[],
wellnessSuggestions: string[],
communitySuggestions: string[],
): Promise<PDFDocument> {
const filePath = "development/testresult.pdf";
const iconPath = "development/live_as_coach_icon.png";
Expand Down Expand Up @@ -213,6 +388,14 @@ async function createPDF(
// Add result PDF to the default PDF
await addResultPDF(pdfDoc, resultsPath);

await addSuggestionsPage(
pdfDoc,
qualitySuggestions,
businessSuggestions,
wellnessSuggestions,
communitySuggestions,
);

await addGuidePDF(pdfDoc, guidePath);

return pdfDoc;
Expand Down Expand Up @@ -267,6 +450,10 @@ exports.readDevTests = functions
const testId = context.params.testId;
const userId = newValue.userId;
const guide = newValue.guide;
const qualitySuggestions = newValue.quality_suggestions;
const businessSuggestions = newValue.business_suggestions;
const wellnessSuggestions = newValue.wellness_suggestions;
const communitySuggestions = newValue.community_suggestions;
functions.logger.log("New test read in dev", testId);

const userReference = await admin.firestore()
Expand All @@ -276,11 +463,26 @@ exports.readDevTests = functions
const userEmail = userData?.email;
const date = newValue?.coachingTestDate;
functions.logger.log("User info", userName, userEmail);
await admin.firestore()
.doc("environments/development/users/"+userId)
.update({status: 5});

const resultsPath = "development/UsersResults/"+userId+".pdf";
const guidePath = "development/"+guide;
const pdfDoc = await createPDF(resultsPath, guidePath, userName, date);
const pdfDoc = await createPDF(
resultsPath,
guidePath,
userName,
date,
qualitySuggestions,
businessSuggestions,
wellnessSuggestions,
communitySuggestions,
);
await sendEmail(pdfDoc, userEmail, userName);
await admin.firestore()
.doc("environments/development/users/"+userId)
.update({status: 6});
});

exports.readStageTests = functions
Expand All @@ -291,6 +493,10 @@ exports.readStageTests = functions
const testId = context.params.testId;
const userId = newValue.userId;
const guide = newValue.guide;
const qualitySuggestions = newValue.quality_suggestions;
const businessSuggestions = newValue.business_suggestions;
const wellnessSuggestions = newValue.wellness_suggestions;
const communitySuggestions = newValue.community_suggestions;
functions.logger.log("New test read in stage", testId);

const userReference = await admin.firestore()
Expand All @@ -303,7 +509,16 @@ exports.readStageTests = functions

const resultsPath = "staging/UsersResults/"+userId+".pdf";
const guidePath = "development/"+guide;
const pdfDoc = await createPDF(resultsPath, guidePath, userName, date);
const pdfDoc = await createPDF(
resultsPath,
guidePath,
userName,
date,
qualitySuggestions,
businessSuggestions,
wellnessSuggestions,
communitySuggestions,
);
await sendEmail(pdfDoc, userEmail, userName);
});

Expand All @@ -315,6 +530,10 @@ exports.readProdTests = functions
const testId = context.params.testId;
const userId = newValue.userId;
const guide = newValue.guide;
const qualitySuggestions = newValue.quality_suggestions;
const businessSuggestions = newValue.business_suggestions;
const wellnessSuggestions = newValue.wellness_suggestions;
const communitySuggestions = newValue.community_suggestions;
functions.logger.log("New test read in production", testId);

const userReference = await admin.firestore()
Expand All @@ -327,6 +546,15 @@ exports.readProdTests = functions

const resultsPath = "production/UsersResults/"+userId+".pdf";
const guidePath = "development/"+guide;
const pdfDoc = await createPDF(resultsPath, guidePath, userName, date);
const pdfDoc = await createPDF(
resultsPath,
guidePath,
userName,
date,
qualitySuggestions,
businessSuggestions,
wellnessSuggestions,
communitySuggestions,
);
await sendEmail(pdfDoc, userEmail, userName);
});
2 changes: 1 addition & 1 deletion lib/coaching_test/models/test_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class CoachingTest {
final completeMap = json.decode(file) as Map<String, dynamic>;
final questionMap = completeMap[question.key] as Map<String, dynamic>?;
final suggestion =
questionMap?[question.answerIndex.toString()] as String?;
questionMap?[(question.answerIndex + 1).toString()] as String?;
return suggestion;
} catch (e) {
return null;
Expand Down

0 comments on commit e565bb8

Please sign in to comment.