Skip to content

Commit

Permalink
"Refresh surveys and combined topline listings" menu action working a…
Browse files Browse the repository at this point in the history
…s expected
  • Loading branch information
motin committed Jan 6, 2020
1 parent 221b4c2 commit c139b4b
Show file tree
Hide file tree
Showing 4 changed files with 420 additions and 85 deletions.
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

### Functions

* [menuRefreshCombinedToplineListing](README.md#menurefreshcombinedtoplinelisting)
* [menuRefreshSurveysAndCombinedToplineListings](README.md#menurefreshsurveysandcombinedtoplinelistings)

## Functions

### menuRefreshCombinedToplineListing
### menuRefreshSurveysAndCombinedToplineListings

**menuRefreshCombinedToplineListing**(): *void*
**menuRefreshSurveysAndCombinedToplineListings**(): *void*

*Defined in [menuActions/menuRefreshCombinedToplineListing.ts:27](https://github.com/Gapminder/gapminder-igno-survey-process-scripts/blob/v0.0.0/src/menuActions/menuRefreshCombinedToplineListing.ts#L27)*
*Defined in [menuActions/menuRefreshSurveysAndCombinedToplineListings.ts:37](https://github.com/Gapminder/gapminder-igno-survey-process-scripts/blob/v0.0.0/src/menuActions/menuRefreshSurveysAndCombinedToplineListings.ts#L37)*

Menu item action for "Gapminder Igno Survey Process -> Refresh combined topline listing"
Menu item action for "Gapminder Igno Survey Process -> Refresh surveys and combined topline listings"

Notes:
- Creates the `surveys` and `topline_combo` worksheets if they don't exist
Expand Down
57 changes: 56 additions & 1 deletion src/gsheetsData/hardcodedConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export const gsResultsFolderName = "gs_results";
/**
* @hidden
*/
export const surveysSheetHeaders = ["survey_name", "file_name"];
export const surveysSheetHeaders = [
"survey_name",
"file_name",
"link_if_found_in_gs_results_folder",
"number_of_rows_in_topline_combo"
];

/**
* @hidden
Expand All @@ -36,3 +41,53 @@ export const combinedToplineSheetHeaders = [
"Metadata",
"Weighted by"
];

/**
* @hidden
*/
export const surveysSheetValueRowToSurveyEntry = (surveysSheetRow: any[]) => {
return {
survey_name: surveysSheetRow[0],
file_name: surveysSheetRow[1],
link_if_found_in_gs_results_folder: surveysSheetRow[2]
};
};

/**
* @hidden
*/
export const surveyEntryToSurveysSheetValueRow = updatedSurveyEntry => [
updatedSurveyEntry.survey_name,
updatedSurveyEntry.file_name,
updatedSurveyEntry.link_if_found_in_gs_results_folder
];

/**
* @hidden
*/
export const combinedToplineSheetValueRowToToplineEntry = (
combinedToplineSheetRow: any[]
) => {
return {
survey_id: combinedToplineSheetRow[0],
question_number: combinedToplineSheetRow[1],
question_text: combinedToplineSheetRow[2],
answer: combinedToplineSheetRow[3],
answer_by_percent: combinedToplineSheetRow[4],
metadata: combinedToplineSheetRow[5],
weighted_by: combinedToplineSheetRow[6]
};
};

/**
* @hidden
*/
export const toplineEntryToCombinedToplineSheetValueRow = toplineEntry => [
toplineEntry.survey_id,
toplineEntry.question_number,
toplineEntry.question_text,
toplineEntry.answer,
toplineEntry.answer_by_percent,
toplineEntry.metadata,
toplineEntry.weighted_by
];
50 changes: 47 additions & 3 deletions src/menuActions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ export function assertCorrectLeftmostSheetColumnHeaders(
const headerRow = sheetDataWithHeaderRow.slice(0, 1);
const firstSheetHeaders = headerRow[0].slice(0, sheetHeaders.length);
if (JSON.stringify(firstSheetHeaders) !== JSON.stringify(sheetHeaders)) {
SpreadsheetApp.getUi().alert(
throw new Error(
`The first column sheetHeaders in '${sheetName}' must be ${JSON.stringify(
sheetHeaders
)} but are currently ${JSON.stringify(
firstSheetHeaders
)}. Please adjust and try again`
);
return false;
}
return true;
}

/**
Expand Down Expand Up @@ -121,3 +119,49 @@ export function addGsheetConvertedVersionOfExcelFileToFolder(
const createdFile = DriveApp.getFileById(createdFileDriveObject.id);
return createdFile;
}

/**
* @hidden
*/
export function ensuredColumnIndex(headers, header: string) {
const index = headers.indexOf(header);
if (index < 0) {
throw new Error(`Header not found: '${header}'`);
}
return index;
}

/**
* @hidden
*/
export function getColumnValuesRange(sheet: Sheet, headers, header) {
const columnIndex = ensuredColumnIndex(headers, header);
return sheet.getRange(2, columnIndex + 1, sheet.getMaxRows() - 1, 1);
}

/**
* @hidden
*/
export function arrayOfASingleValue(value, len): any[] {
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(value);
}
return arr;
}

/**
* From https://stackoverflow.com/a/43046408/682317
* @hidden
*/
export function unique(ar) {
const j = {};

ar.forEach(v => {
j[v + "::" + typeof v] = v;
});

return Object.keys(j).map(v => {
return j[v];
});
}
Loading

0 comments on commit c139b4b

Please sign in to comment.