Skip to content

Commit

Permalink
rename "tag" to "file" and "sheetName" to "tab" for generality (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToddFincannon committed Jul 12, 2021
1 parent 1dc68a9 commit e47d911
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/EquationGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ export default class EquationGen extends ModelReader {
// If direct data exists for this variable, copy it from the workbook into one or more lookups.
let result = []
if (this.mode === 'init-lookups') {
let { tag, sheetName, timeRowOrCol, startCell } = this.var.directDataArgs
let workbook = this.directData.get(tag)
let { file, tab, timeRowOrCol, startCell } = this.var.directDataArgs
let workbook = this.directData.get(file)
if (workbook) {
let sheet = workbook.Sheets[sheetName]
let sheet = workbook.Sheets[tab]
if (sheet) {
let indexNum = 0
if (!R.isEmpty(this.var.subscripts)) {
Expand All @@ -344,10 +344,10 @@ export default class EquationGen extends ModelReader {
}
result.push(this.generateDirectDataLookup(sheet, timeRowOrCol, startCell, indexNum))
} else {
throw new Error(`ERROR: Direct data worksheet ${sheetName} tagged ${tag} not found`)
throw new Error(`ERROR: Direct data worksheet ${tab} tagged ${file} not found`)
}
} else {
throw new Error(`ERROR: Direct data workbook tagged ${tag} not found`)
throw new Error(`ERROR: Direct data workbook tagged ${file} not found`)
}
}
return result
Expand Down
8 changes: 6 additions & 2 deletions src/EquationReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ export default class EquationReader extends ModelReader {
this.expandDelayFunction(fn, args)
} else if (fn === '_GET_DIRECT_DATA') {
// Extract string constant arguments into an object used in code generation.
// For Excel files, the file argument names an indirect "?" file tag from the model settings.
// For CSV files, it gives a relative pathname in the model directory.
// For Excel files, the tab argument names an Excel worksheet.
// For CSV files, it gives the delimiter character.
let args = R.map(
arg => matchRegex(arg, /'(.*)'/),
R.map(expr => expr.getText(), ctx.expr())
)
this.var.directDataArgs = {
tag: args[0],
sheetName: args[1],
file: args[0],
tab: args[1],
timeRowOrCol: args[2],
startCell: args[3]
}
Expand Down
6 changes: 3 additions & 3 deletions src/sde-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ export let generate = async (model, opts) => {
extData = new Map([...extData, ...data])
}
}
// Attach Excel workbook data to directData entries by tag name.
// Attach Excel workbook data to directData entries by file name.
let directData = new Map()
if (spec.directData) {
for (let [tag, xlsxFilename] of Object.entries(spec.directData)) {
for (let [file, xlsxFilename] of Object.entries(spec.directData)) {
let pathname = path.join(modelDirname, xlsxFilename)
directData.set(tag, readXlsx(pathname))
directData.set(file, readXlsx(pathname))
}
}
// Produce a runnable model with the "genc" and "preprocess" options.
Expand Down

0 comments on commit e47d911

Please sign in to comment.