From 2ef150a3ea675b91c7c65709f10257e48eb7cc19 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 18 Jun 2019 01:03:20 +0200 Subject: [PATCH] Ref T658, improved matching script examples --- ...xt => _Do not store your scripts here.txt} | 0 .../matchingscript/changeAirline.reverse.js | 34 +++++++++++ .../share/matchingscript/demo.matching.js | 60 ++++++++++++++++++ .../{reverseDemo.js => demo.reverse.js} | 0 .../share/matchingscript/matchingDemo.js | 61 ------------------- .../neutralAircraft.matching.js | 58 ++++++++++++++++++ resources/share/matchingscript/stub.js | 25 ++++++++ 7 files changed, 177 insertions(+), 61 deletions(-) rename resources/share/matchingscript/{Do not store your scripts here.txt => _Do not store your scripts here.txt} (100%) create mode 100644 resources/share/matchingscript/changeAirline.reverse.js create mode 100644 resources/share/matchingscript/demo.matching.js rename resources/share/matchingscript/{reverseDemo.js => demo.reverse.js} (100%) delete mode 100644 resources/share/matchingscript/matchingDemo.js create mode 100644 resources/share/matchingscript/neutralAircraft.matching.js create mode 100644 resources/share/matchingscript/stub.js diff --git a/resources/share/matchingscript/Do not store your scripts here.txt b/resources/share/matchingscript/_Do not store your scripts here.txt similarity index 100% rename from resources/share/matchingscript/Do not store your scripts here.txt rename to resources/share/matchingscript/_Do not store your scripts here.txt diff --git a/resources/share/matchingscript/changeAirline.reverse.js b/resources/share/matchingscript/changeAirline.reverse.js new file mode 100644 index 000000000..7ab5527d2 --- /dev/null +++ b/resources/share/matchingscript/changeAirline.reverse.js @@ -0,0 +1,34 @@ +// This is a demo file demonstrating some capabilities of the +// matching script engine +// This script runs after(!) the reverse lookup has been completed +// +// inObject values as from network +// outObject to be returned back to matching engine +// matchedObject the result so far, same as inObject for reverse lookup +// modelSet user's current model set, not available in reverse lookup +// webServices wraps access to swift web services +// +// outObject.rerun = true => rerun matching or reverse lookup after the value has been changed again, like a 2nd pass +// outObject.modified = true => tell matching or reverse lookup that something has been changed +// +(function () { + // avoid breaking matching/reverse lookup + try { + // EASYJET? + if (inObject.airlineIcao === "EJU") { + outObject.airlineIcao = "EZY"; + outObject.dbAirlineIcaoId = 2217; + outObject.logMessage = "Changing EJU to EZY"; // display log + outObject.modelString = ""; // invalidate any model + outObject.dbModelId = -1; // invalidate + outObject.modified = true; + outObject.rerun = true; // treat the changed values as coming from network + } else { + outObject.logMessage = "No airline change, keeping " + inObject.airlineIcao; + } + } catch (err) { + return err.toString(); + } + + return outObject; +}) diff --git a/resources/share/matchingscript/demo.matching.js b/resources/share/matchingscript/demo.matching.js new file mode 100644 index 000000000..b8a7e1b5e --- /dev/null +++ b/resources/share/matchingscript/demo.matching.js @@ -0,0 +1,60 @@ +// This is a demo file demonstrating some capabilities of the +// matching script engine +// This script runs after(!) the matching has been completed +// +// inObject values as from network +// outObject to be returned back to matching engine +// matchedObject the result so far, same as inObject for reverse lookup +// modelSet user's current model set, not available in reverse lookup +// webServices wraps access to swift web services +// +// outObject.rerun = true => rerun matching or reverse lookup after the value has been changed again, like a 2nd pass +// outObject.modified = true => tell matching or reverse lookup that something has been changed +// +(function () { + // avoid breaking matching/reverse lookup + try { + + // the logic we implement + var lm = ""; + if (inObject.callsign === 'DAMBZ') { + var ms = "PIPER CHEROKEE 180"; // must exist in model set + if (modelSet.containsModelString(ms)) { + lm = "Model set contains "; + lm += ms; + outObject.modelString = ms; + outObject.modified = true; // tell we have changed the values + lm += ". Changed model for DAMBZ"; + } + } else { + if (inObject.hasAirlineIcao) { + if (matchedObject.hasUnmodifiedDesignators) { + lm = "Model with exact aircraft " + inObject.aircraftIcao + " airline " + inObject.virtualAirlineIcao; + } else { + var combinedType = inObject.combinedType; + var white = "ffffff"; + var mscl = modelSet.findCombinedTypeWithClosestColorLivery(combinedType, white); + if (!mscl || 0 === mscl.length) { + // not found + mscl = "PIPER CHEROKEE 180"; // some hardcoded value + lm = "No color livery model found for " + combinedType + ". Using: " + mscl; + } else { + lm = "Color livery model found for " + combinedType + ": " + mscl; + } + outObject.modelString = mscl; + outObject.modified = true; // tell we have changed the values + } + } else { + // no airline, so most likely some small or military aircraft + lm = "Model without airline"; + } + } + + outObject.logMessage = lm; // display log + + } catch (err) { + return err.toString(); + } + + return outObject; +}) diff --git a/resources/share/matchingscript/reverseDemo.js b/resources/share/matchingscript/demo.reverse.js similarity index 100% rename from resources/share/matchingscript/reverseDemo.js rename to resources/share/matchingscript/demo.reverse.js diff --git a/resources/share/matchingscript/matchingDemo.js b/resources/share/matchingscript/matchingDemo.js deleted file mode 100644 index 91b7c7b58..000000000 --- a/resources/share/matchingscript/matchingDemo.js +++ /dev/null @@ -1,61 +0,0 @@ -// This is a demo file demonstrating some capabilities of the -// matching script engine -// This script runs after(!) the matching has been completed -// -// inObject values as from network -// outObject to be returned back to matching engine -// matchedObject the result so far, same as inObject for reverse lookup -// modelSet user's current model set, not available in reverse lookup -// webServices wraps access to swift web services -// -// outObject.rerun = true => rerun matching or reverse lookup after the value has been changed again, like a 2nd pass -// outObject.modified = true => tell matching or reverse lookup that something has been changed -// -(function() { - // avoid breaking matching/reverse lookup - try { - - // the logic we implement - var lm = ""; - if (inObject.callsign === 'DAMBZ') { - var ms = "PIPER CHEROKEE 180"; // must exist in model set - if (modelSet.containsModelString(ms)) { - lm = "Model set contains "; - lm += ms; - outObject.modelString = ms; - outObject.modified = true; // tell we have changed the values - lm += ". Changed model for DAMBZ"; - } - } else { - if (inObject.hasAirlineIcao) { - if (matchedObject.hasUnmodifiedDesignators) { - lm = "Model with exact aircraft " + inObject.aircraftIcao + " airline " + inObject.virtualAirlineIcao; - } else { - var combinedType = inObject.combinedType; - var white = "ffffff"; - var mscl = modelSet.findCombinedTypeWithClosestColorLivery(combinedType, white); - if (!mscl || 0 === mscl.length) { - // not found - mscl = "PIPER CHEROKEE 180"; // some hardcoded value - lm = "No color livery model found for " + combinedType + ". Using: " + mscl; - } else { - lm = "Color livery model found for " + combinedType + ": " + mscl; - } - outObject.modelString = mscl; - outObject.modified = true; // tell we have changed the values - } - } else { - // no airline, so most likely some small or military aircraft - lm = "Model without airline"; - } - } - - outObject.logMessage = lm; // display log - return outObject; - -} -catch(err) { - return err.toString(); -} - -}) diff --git a/resources/share/matchingscript/neutralAircraft.matching.js b/resources/share/matchingscript/neutralAircraft.matching.js new file mode 100644 index 000000000..141f2621b --- /dev/null +++ b/resources/share/matchingscript/neutralAircraft.matching.js @@ -0,0 +1,58 @@ +// This is a demo file demonstrating some capabilities of the +// matching script engine +// This script runs after(!) the matching has been completed +// +// inObject values as from network +// outObject to be returned back to matching engine +// matchedObject the result so far, same as inObject for reverse lookup +// modelSet user's current model set, not available in reverse lookup +// webServices wraps access to swift web services +// +// outObject.rerun = true => rerun matching or reverse lookup after the value has been changed again, like a 2nd pass +// outObject.modified = true => tell matching or reverse lookup that something has been changed +// +(function () { + // avoid breaking matching/reverse lookup + try { + // the logic we implement + var lm = ""; + if (inObject.hasAirlineIcao) { + if (matchedObject.hasUnmodifiedDesignators) { + lm = "Model with exact aircraft " + inObject.aircraftIcao + " airline " + inObject.virtualAirlineIcao; + } else if (!matchedObject.hasModifiedAircraftFamily && !matchedObject.hasModifiedAirlineIcaoDesignator) { + lm = "Model matching with same family " + matchedObject.aircraftFamily + " and airline " + matchedObject.airlineIcao; + } else if (!matchedObject.hasModifiedAirlineIcaoDesignator) { + lm = "Model matching with same airline: " + matchedObject.aircraftIcao + "/" + matchedObject.airlineIcao; + } else { + var combinedType = inObject.combinedType; + var family = inObject.aircraftFamily; + var searchColor = "ffffff"; + var mscl = modelSet.findAircraftFamilyWithClosestColorLivery(family, searchColor); + if (mscl && 0 > mscl.length) { + lm = "Color livery model found for " + combinedType + ": " + mscl; + } else { + mscl = modelSet.findClosestCombinedTypeWithClosestColorLivery(combinedType, searchColor); + if (!mscl || 0 === mscl.length) { + // not found + mscl = "PIPER CHEROKEE 180"; // some hardcoded value, change to your preferred default + lm = "No color livery model found for " + combinedType + ". Using hardcoded: " + mscl; + } else { + lm = "Color livery model found for " + combinedType + ": " + mscl; + } + } + outObject.modelString = mscl; + outObject.modified = true; // tell we have changed the values + } + } else { + // no airline, so most likely some small or military aircraft + lm = "Model without airline"; + } + + outObject.logMessage = lm; // display log + + } catch (err) { + return err.toString(); + } + + return outObject; +}) diff --git a/resources/share/matchingscript/stub.js b/resources/share/matchingscript/stub.js new file mode 100644 index 000000000..daf2d5727 --- /dev/null +++ b/resources/share/matchingscript/stub.js @@ -0,0 +1,25 @@ +// This is a demo file demonstrating some capabilities of the +// matching script engine +// This script runs after(!) the matching has been completed +// +// inObject values as from network +// outObject to be returned back to matching engine +// matchedObject the result so far, same as inObject for reverse lookup +// modelSet user's current model set, not available in reverse lookup +// webServices wraps access to swift web services +// +// outObject.rerun = true => rerun matching or reverse lookup after the value has been changed again, like a 2nd pass +// outObject.modified = true => tell matching or reverse lookup that something has been changed +// +(function () { + // avoid breaking matching/reverse lookup + try { + + outObject.logMessage = "matching script"; // display log + + } catch (err) { + return err.toString(); + } + + return outObject; +})