Uploaded by Ayan

bakerfranke code sample

advertisement
5/1/23, 7:51 PM
https://bakerfranke.github.io/codePrint/
busyflyer
// On click of the submit button, execute the below statement
onEvent("submit", "click", function(){
var userCountry=getText("Country"); // get the user input country
var userYear=getNumber("Year"); // get the user input year
plotfunction(userCountry,userYear); //call the user defined function to plot the chart
});
function plotfunction(userCountry,userYear){
//set chart options
var mychartOptions={};
mychartOptions.bars="vertical";
mychartOptions.title="Busiest Airport and Travellers";
mychartOptions.colors=["green", "red"];
mychartOptions.legend={position: "none"};
var airportData={};
//print console log to see if the variable stores the right data
console.log("Country:" + userCountry);
console.log("Year:" + userYear);
// check if user has selected valid country from the drop down list
if(userCountry != "Country") {
// read all the records from temporary database/list and delete them all
readRecords("airportDatadb", {}, function(recordsdel) {
console.log("Total Records from airportDatadb:" + recordsdel.length);
if (recordsdel.length>0) {
for (var i =0; i < recordsdel.length; i++) {
console.log("Deleting Records from airportDatadb:" + i);
//delete records from temporary database/list airportDatadb
deleteRecord("airportDatadb", {id:recordsdel[i].id});
}
}
else {
console.log("There are no records to delete");
}
});
// read all the records froom busiest airports database/list for the user input country and ye
readRecords("Busiest Airports", {Country:userCountry,Year:userYear}, function(record) {
console.log("Total Records from Busiest Airports:" + record.length);
// if there are available records for the given country and year then read and store in temporar
if (record.length>0) {
// loop through all the read records one by one
for (var i =0; i < record.length; i++) {
// assign the record values to a variable
https://bakerfranke.github.io/codePrint/
1/2
5/1/23, 7:51 PM
53
54
55
56
57
58
59
60
61
https://bakerfranke.github.io/codePrint/
airportData.location = record[i].Location;
airportData.passengers = record[i].TotalPassengers;
airportData.country = record[i].Country;
console.log("country:" + record[i].Country + " location:" + record[i].Location + "
//create the read record in temporary database/list
createRecordSync("airportDatadb", airportData);
}
}
else {
write("There are no records to read");
62
}
63
64
65
// execute the draw chart function and pass the database/list and chart options to
drawChartFromRecords("aiportBarchart", "bar", "airportDatadb", ["location", "passengers"
66
67
68
69
70
71
72
73
74
});
}
else{
//throw error on screen if user picked wrong country code
write("Pick a country from the dropdown list");
}
}
PDF document made with CodePrint using Prism
https://bakerfranke.github.io/codePrint/
2/2
Download