Download Fortify export data using the API - javascript

Objective
To generate CSV "export data" files from within Fortify, then download them.
Steps
Generate the (csv) export data using, that works fine:
https://SERVER:8443/ssc/api/v1/dataExports/action
Download the csv file using:
https://SERVER:8443/ssc/transfer/reportDownload.html - GET
Problem
I'm facing an issue with step 2, export being successfully generated. I can't seem to download them.
I'm requesting :
https://SERVER:8443/ssc/api/v1/fileTokens
with the payload : { fileTokenType : "REPORT_FILE" }
I obtain:
YzFmOWY4ZjMtZjU2MS00ZTU0XXXXXXXXXXXXX
Yet as per the documentation, I should get something like:
7e8d912e-2432-6496-3232-709b05513bf2
As a result when I attempt to GET my file with the following request:
https://SERVER:8443/ssc/transfer/reportDownload.html?mat=YzFmOWY4ZjMtZjU2MS00ZTU0XXXXXXXXXXXXX&id=449741
I get a 500 error.
Questions
What do you guys get when you request: https://SERVER:8443/ssc/api/v1/fileTokens?
Is the documentation not exactly correct?
If not, what do you reckon I am doing wrong?

Found the solution, the correct link is
dataExportDownload.html
instead of:
reportDownload.html

Related

Basic training of ML5 neural network not working

I am using ML5 to train a Neural Network.
I am loading a CSV file with data from the Titanic. This works when I download the demo file from the ML5 GitHub.
But when I use a different CSV file, and I replace the column names in my code, it stops working. Am I missing something? Is it a problem that my CSV file contains numbers, while the demo file contains strings?
let neuralNetwork
function start() {
const nnOptions = {
dataUrl: "data/titanic.csv",
inputs: ["Pclass", "Sex", "Age", "SibSp"], // labels from my CSV file
outputs: ["Survived"],
task: "classification",
debug: true,
};
neuralNetwork = ml5.neuralNetwork(nnOptions, modelReady);
}
function modelReady() {
neuralNetwork.normalizeData();
neuralNetwork.train({ epochs: 50 }, whileTraining, finishedTraining);
}
// this doesn't get called at all
function whileTraining(epoch, logs) {
console.log(`Epoch: ${epoch} - loss: ${logs.loss.toFixed(2)}`);
}
// this gets called immediately
function finishedTraining() {
console.log("done!");
}
start()
The console immediately shows "done!", but the model is not trained. There is no error message.
The strange thing is, when a label name is incorrect, then I do get an error. So the label names are actually recognised.
Original CSV file, working:
survived,fare_class,sex,age,fare
died,first,male,39,0
died,first,male,29,0
My CSV file, not working:
Survived,Pclass,Sex,Age,SibSp,Parch,Fare,Embarked
0,3,1,22.0,1,0,7.25,1
1,1,0,38.0,1,0,71.2833,2
Just in case anyone runs into this issue: when you are classifying, the label always has to be a string....
Working CSV file:
Survived,Pclass,Sex,Age,SibSp,Parch,Fare,Embarked
yes,3,1,22.0,1,0,7.25,1
no,1,0,38.0,1,0,71.2833,2
I'm not sure if this would help but from what I learned is that all the inputs should be numbers. But if the demo works then it the code should work. When it comes to ML5 you have to pay attention to the CSV file. make sure the output that you are trying to predict is a string. if ur using a csv with only numbers and are trying to predict a number as output then you should change the task: classification to regression. you can also give this code a try if you would like to:

Resolve a 301 redirect and store the url for future use javascript

So I have a script that organises an un-formatted csv file and presents an output.
One of the pieces of data I receive in this data that we must return is a link to an image stored on Google Drive. The problem with this is Google Drive doesn't like to present you with a direct link to a file.
You can get the ID of a file (e.g. abc123DEFz) and view it online at https://drive.google.com/open?id=abc123DEFz. We need a direct link for another service to be able to process the file, not a redirect or some fancy website.
After poking around I discovered that https://drive.google.com/uc?export=view&id=abc123DEFz would redirect you directly to the file, and was what I somehow had to obtain inside the script.
The url it gave me though didn't really seem to have any relation to the ID and I couldn't just go ahead and swap the ID, for each file I would have to resolve this uc?export link into this link that would send me directly to the file. (Where the redirect sent me: http://doc-0c-2s-docs.googleusercontent.com/docs/securesc/32-char-long-alphanumeric-thing/another-32-char-long-alphanumeric-thing/1234567891234/12345678901234567890/12345678901234567890/abc123DEFz?e=view&authuser=0&nonce=abcdefgh12345&user=12345678901234567890&hash=32-char-long-alphanumeric-hash)
No authentication is required to access the file, it is public.
My script works like this:
const csv = require('csv-parser'),
fs = require('fs'),
request = require('request');
let final = [],
spuSet = [];
fs.createReadStream('data.csv')
.pipe(csv())
.on('data', (row) => {
>> data processing stuff, very boring so you don't care
console.log(`
I'm now going to save this information and tell you about the row I'm processing
so you can see why something went wrong`);
final.push(`[{"yes":"there is something here"},{"anditinvolves":${thatDataIJustGot}]`);
spuSet.push(`[{"morethings":123}]`);
})
.on('end', () => {
console.log('CSV file successfully processed');
console.log(`
COMPLETED! Check the output below and verify:
[${String(final).replace(/\r?\n|\r/g, " ")}]
COMPLETED! Check the output below and verify:
[${String(spuSet).replace(/\r?\n|\r/g, " ")}]`);
>> some more boring stuff where I upload the data somewhere and create a file containing said data
});
I tried using requests but it's a function with a callback so using the data outside of the function would be difficult, and wrapping everything inside the function would remove my ability to push to the array.
The url I get from the redirect would be included in the data I am pushing to the array for me to use later on.
I'm pretty bad at explaining crap, if you have any questions please ask.
Thanks in advance for any help you can give.
Try using the webContentLink parameter of the Get API call:
var webLink = drive.files.get({
fileId: 'fileid',
fields: 'webContentLink'
});
This will return the object:
{
"webContentLink": "https://drive.google.com/a/google.com/uc?id=fileId&export=download"
}
Then you can use split() to remove &export=download from the link, as we don't want to download it.
As fileId, you can get the Ids of your files by using the List API Call, and then you can loop through the list array calling the files.get from the first step.
My apologies if I misunderstood your issue.
In case you need help with the authentication to the Google Services, you can take a look at the Quickstart

Read list from a text file js

Hello i'm trying to read this list from a file
this
this.testJson = {
list:[
{src:"x1.jpg",title:"x1",song:"x1.mp3"},
{src:"x2.jpg",title:"x2",song:"x2.mp3"},
{src:"x3.jpg",title:"x3",song:"x3.mp3"},
{src:"x4.jpg",title:"x4",song:"x4.mp3"}
]
}
to
this.testJson = {
list:[
// read x.txt or x.txt from a URL
]
}
and x.txt contain
{src:"x1.jpg",title:"x1",song:"x1.mp3"},
{src:"x2.jpg",title:"x2",song:"x2.mp3"},
{src:"x3.jpg",title:"x3",song:"x3.mp3"},
{src:"x4.jpg",title:"x4",song:"x4.mp3"}
as i do not have any java script experience , can somebody help me with this ?
thanks in advance
You have to expose that file from a web-server so your JavaScript can make an http request on that file.
To load resources from JavaScript you have to make an XMLHttpRequest or better known as AJAX request.
Actually this requires some setup so using a library would be easier. My favourite one is axios. It has a really simple API and handles response parse as well, so when you load axios on your web-site this is an approach you might follow :
axios.get('path-to-file').then(function(response){
this.testJson.list = response.data
});
Note that your x.txt does not seem like a valid JSON. It has to be a valid one so axios can parse it. If you decide to parse the file on your own you have to use JSON API.

Three .json files 'StockChart' - highcharts

Please help by taking StockChart. Pinning three .json files as in the example , But does not work. The code is below:
www.jsfiddle.net/d8xwjxg7/2
You have an error in your code:
$.getJSON('http://www.iklimat.pl/'+name()+'.php', function (data) {
Should be:
$.getJSON('http://www.iklimat.pl/'+ name +'.php', function (data) {
Since name is a string not a function.
Also, this will not work in a JSFiddle since you cannot load files not from the site the javascript is running on without the endpoint you are accessing setting the access-allow-control-origin header.
EDIT:
I have sorted out the issue you were having getting data, however there is an issue with that data.
http://jsfiddle.net/d8xwjxg7/5/

Unable to parse report in dhtmlx grid

On calling grid.parse(jsonstr, 'json') in js code the report is not getting displayed nor it throws any error though all the headers are getting displayed. Code below:
function getReportData(data) {
var gr = new dhtmlXGridObject('gridbox');
gr.selMultiRows = true;
gr.setHeader(data['tVals']['header']);
gr.setInitWidths(data['tVals']['init_widths']);
gr.setColAlign(data['tVals']['col_align']);
gr.setColTypes(data['tVals']['col_types']);
gr.setColSorting("str,str");
gr.init();
gr.parse(data['gData'], 'json');
}
PS: data has all the relevant information required by the code.
Also my html has following js imports:
dhtmlxcommon.js
dhtmlxgrid.js
dhtmlxgridcell.js
dhtmlxtreegrid.js
dhtmlxgrid_json.js
dhtmlxgrid_hextra.js
jquery version 1.6.1
The issue is seems to be in the format of your JSON. Can you provide a sample of your JSON string?
You can find an example of valid JSON supported by dhtmlxGrid here:
http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:syntax_templates#json_format_details
It would really help if you posted your JSON format, however I think I know what your problem is:
There are two formats of JSON that you can use in DHTMLX ( more details on https://docs.dhtmlx.com/grid__data_formats.html#jsonformat)
So the solution to your issue should be very simple.
Change
gr.parse(data['gData'], 'json');
to
gr.parse(data['gData'], 'js');

Categories