Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in Data #3815

Merged
merged 5 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/javascript/gobierto_data/lib/factories/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import axios from "axios";
const endPoint = `${baseUrl}/data.csv`;
const token = getToken();
const headers = {
"Content-type": "application/json",
Authorization: token
};

Expand Down
1 change: 0 additions & 1 deletion app/javascript/gobierto_data/webapp/components/Dataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ export default {
}

this.currentQuery = sql;
this.runCurrentQuery();
},
storeRecentQuery() {
// if the currentQuery does not exist, nor recent, nor in stored queries neither
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default {
}
}
},
created() {
this.worker = perspective.worker();
},
mounted() {
this.viewer = this.$refs["perspective-viewer"];
this.checkIfQueryResultIsEmpty(this.items)
Expand All @@ -84,70 +87,40 @@ export default {
}
},
checkPerspectiveTypes() {
//Get columns generates from query
const arrayColumnsFromQuery = this.arrayColumnsQuery
//Get columns from API
const arrayColumnsFromAPI = Object.keys(this.objectColumns)

/* We compare the columns, if it returns true we pass the schema to Perspective, if false Perspective will convert the columns*/
const sameColumns = arrayColumnsFromAPI.length === arrayColumnsFromQuery.length && arrayColumnsFromAPI.every(column => arrayColumnsFromQuery.includes(column))

//If columns contains Boolean values goes to replace them
let replaceItems = this.items
if (Object.values(this.objectColumns).some(value => value === "boolean")) {
replaceItems = this.items.replace(/"t"/g, '"true"').replace(/"f"/g, '"false"')
}

if (sameColumns) {
this.initPerspectiveWithSchema(replaceItems)
} else {
this.initPerspective(replaceItems)
}
this.initPerspectiveWithSchema(replaceItems)
},
initPerspectiveWithSchema(data) {
this.viewer.setAttribute('plugin', this.typeChart)
this.viewer.clear();

const transformColumns = this.objectColumns

Object.keys(transformColumns).forEach((key) => {
if (transformColumns[key] === 'hstore' || transformColumns[key] === 'jsonb' || transformColumns[key] === 'text') {
transformColumns[key] = 'string'
} else if (transformColumns[key] === 'decimal') {
transformColumns[key] = 'float'
} else if (transformColumns[key] === 'inet') {
transformColumns[key] = 'integer'
//In some cases, Perspective throw an error when tried to convert column with date format, so we need to change the date to datetime
} else if (transformColumns[key] === 'date') {
transformColumns[key] = 'datetime'
} else if (transformColumns[key] === 'tsvector') {
transformColumns[key] = 'string'
const schema = this.objectColumns

Object.keys(schema).forEach((key) => {
if (['text', 'hstore', 'jsonb', 'tsvector'].includes(schema[key])) {
schema[key] = 'string'
} else if (schema[key] === 'decimal') {
schema[key] = 'float'
} else if (schema[key] === 'inet') {
schema[key] = 'integer'
} else if (schema[key] === 'date') {
schema[key] = 'datetime'
}
});

let schema = transformColumns

const loadSchema = this.viewer.worker.table(schema);
this.viewer.load(loadSchema)
this.viewer.update(data)

if (this.config) {
this.loadConfig()
}

this.listenerPerspective()
},
initPerspective(data) {
this.viewer.setAttribute('plugin', this.typeChart)
this.viewer.clear();

this.worker.table(schema);
this.viewer.load(data)

if (this.config) {
this.loadConfig()
}

this.listenerPerspective()
},
loadConfig() {
this.viewer.restore(this.config);
Expand Down