Good evening everyone!
Anyone knows how to extract the top 5 numbers (the highest) from an array?
I have an XML with names, surnames and score and want to extract the top 5 to create a chart.
As for now, I am getting all the info in this way:
num = xmlData.childNodes.length;
for (var i = 0; i <= num - 1; i++)
{
names[i] = this.childNodes[i].childNodes[6].firstChild.nodeValue;
surnames[i] = this.childNodes[i].childNodes[5].firstChild.nodeValue;
points[i] = this.childNodes[i].childNodes[0].firstChild.nodeValue;
pointsint[i] = parseInt(speeds[i]);
trace(i + "." + pointsint[i] + " (" + names[i] + " " + surnames[i] + ")");
}
Thank you for any help!
Organize data as generic object entries and Array.sortOn(...) (http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7ea5.html). I didn't test it but I think the idea is clear:
var num = xmlData.childNodes.length;
var entries = [];
for (var i = 0; i <= num - 1; i++)
{
var anEntry = {};
var aNode = xmlData.childNodes[i];
anEntry['name'] = aNode.childNodes[6].firstChild.nodeValue;
anEntry['surname'] = aNode.childNodes[5].firstChild.nodeValue;
var aSpeed = aNode.childNodes[0].firstChild.nodeValue;
anEntry['speed'] = parseInt(aSpeed);
entries.push(anEntry);
trace(i + "." + anEntry['speed'] + " (" + anEntry['name'] + " " + anEntry['surname'] + ")");
}
entries.sortOn("speed", Array.DESCENDING | Array.NUMERIC);
// Now first five elements of entries Array is what you want.
Related
I'm trying to write the array to a single column, but despite everything seems right to me, it keeps throwing me an error:
Here's the piece of code:
function getGFTickersData() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LIST OF STOCKS");
var tickerRng = ss.getRange(2, 1, ss.getLastRow(), 1).getValues();
//var TDSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TickersData");
var TDSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet10");
var tickerArr = [];
for (var b = 0; b < tickerRng.length; b++) {
var tickerToArr = [tickerRng[b]];
if (tickerToArr != '') {
var gFinFormula = "=query(googlefinance(" + '"' + tickerToArr + '"' + ",'all shares'!A4,'all shares'!D3,'all shares'!D4,'all shares'!D5)," + '"' + "select *" + '"' + ",1)";
var repeated = [].concat(... new Array(105).fill(tickerToArr))
tickerArr.push(repeated)
}
}
Logger.log(tickerArr[0]);
TDSheet.getRange(TDSheet.getLastRow() + 1, 1, tickerArr.length, 1).setValues(tickerArr);
}
Appreciate any pointers!
From your following replying,
The array is composed of about 200k element, each showing in the array 105 times. I want to write all of them, one on the top of the other in a single column.
How about the following modification?
From:
tickerArr.push(repeated)
To:
tickerArr = tickerArr.concat(repeated);
References:
push()
concat()
In the code below, I am trying to read in a 2d array (157 rows, 2 columns), which are all formulas. I need to then delete a part of the formula from each cell, then write it back to the sheet in the same range (prior to this step, I am deleting the sheet that this portion of the formula is referencing). When I run the debugger, everything runs fine, but my values do not get replaced. Any thoughts?
ss.setActiveSheet(ss.getSheetByName('Employee List'));
var as = SpreadsheetApp.getActiveSheet();
var empid = as.getLastRow();
var hrsRange = as.getRange(1, 3, empid, 2).getFormulas();
var i = 1;
while(i < empid)
{
var emp = as.getRange(i, 2).getA1Notation();
if (cpr == 20)
{
while(i < hrsRange.length)
{
var regHrs = "+sumif('" + array[x] + "'!O:O,$" + emp + ",'" + array[x] + "'!P:P)";
var otHrs = "+sumif('" + array[x] + "'!O:O,$" + emp + ",'" + array[x] + "'!Q:Q)";
hrsRange[i-1][0].toString().replace(regHrs,"");
hrsRange[i-1][1].toString().replace(otHrs,"");
i++;
}
} else {
while(i < hrsRange.length)
{
var regHrs = "+sumif('" + array[x] + "'!O:O,$" + emp + ",'" + array[x] + "'!Q:Q)";
var otHrs = "+sumif('" + array[x] + "'!O:O,$" + emp + ",'" + array[x] + "'!R:R)";
hrsRange[i-1][0].toString().replace(regHrs,"");
hrsRange[i-1][1].toString().replace(otHrs,"");
i++;
}
}
i++;
}
as.getRange(1, 3, empid, 2).setFormulas(hrsRange);
This line:
hrsRange[i-1][0].toString().replace(regHrs,"");
will return a string, not actually modify hrsRange[i-1][0] .
You'll need to assign the resulting string to hrsRange[i-1][0]:
hrsRange[i-1][0]=hrsRange[i-1][0].toString().replace(regHrs,"");
Here is the indices code:
`
g = TitanFactory.build().set("storage.backend", "cassandra")
.set("storage.hostname", "127.0.0.1").open();
TitanManagement mgmt = g.getManagementSystem();
PropertyKey db_local_name = mgmt.makePropertyKey("db_local_name")
.dataType(String.class).make();
mgmt.buildIndex("byDb_local_name", Vertex.class).addKey(db_local_name)
.buildCompositeIndex();
PropertyKey db_schema = mgmt.makePropertyKey("db_schema")
.dataType(String.class).make();
mgmt.buildIndex("byDb_schema", Vertex.class).addKey(db_schema)
.buildCompositeIndex();
PropertyKey db_column = mgmt.makePropertyKey("db_column")
.dataType(String.class).make();
mgmt.buildIndex("byDb_column", Vertex.class).addKey(db_column)
.buildCompositeIndex();
PropertyKey type = mgmt.makePropertyKey("type").dataType(String.class)
.make();
mgmt.buildIndex("byType", Vertex.class).addKey(type)
.buildCompositeIndex();
PropertyKey value = mgmt.makePropertyKey("value")
.dataType(Object.class).make();
mgmt.buildIndex("byValue", Vertex.class).addKey(value)
.buildCompositeIndex();
PropertyKey index = mgmt.makePropertyKey("index")
.dataType(Integer.class).make();
mgmt.buildIndex("byIndex", Vertex.class).addKey(index)
.buildCompositeIndex();
mgmt.commit();`
Here is the search for vertices and then add vertex with 3 edges on 3GHz 2GB RAM pc. It does 830 vertices in 3 hours and I have 100,000 data its too slow. The code is below:
for (Object[] rowObj : list) {
// TXN_ID
Iterator<Vertex> iter = g.query()
.has("db_local_name", "Report Name 1")
.has("db_schema", "MPS").has("db_column", "txn_id")
.has("value", rowObj[0]).vertices().iterator();
if (iter.hasNext()) {
vertex1 = iter.next();
logger.debug("vertex1=" + vertex1.getId() + ","
+ vertex1.getProperty("db_local_name") + ","
+ vertex1.getProperty("db_schema") + ","
+ vertex1.getProperty("db_column") + ","
+ vertex1.getProperty("type") + ","
+ vertex1.getProperty("index") + ","
+ vertex1.getProperty("value"));
}
// TXN_TYPE
iter = g.query().has("db_local_name", "Report Name 1")
.has("db_schema", "MPS").has("db_column", "txn_type")
.has("value", rowObj[1]).vertices().iterator();
if (iter.hasNext()) {
vertex2 = iter.next();
logger.debug("vertex2=" + vertex2.getId() + ","
+ vertex2.getProperty("db_local_name") + ","
+ vertex2.getProperty("db_schema") + ","
+ vertex2.getProperty("db_column") + ","
+ vertex2.getProperty("type") + ","
+ vertex2.getProperty("index") + ","
+ vertex2.getProperty("value"));
}
// WALLET_ID
iter = g.query().has("db_local_name", "Report Name 1")
.has("db_schema", "MPS").has("db_column", "wallet_id")
.has("value", rowObj[2]).vertices().iterator();
if (iter.hasNext()) {
vertex3 = iter.next();
logger.debug("vertex3=" + vertex3.getId() + ","
+ vertex3.getProperty("db_local_name") + ","
+ vertex3.getProperty("db_schema") + ","
+ vertex3.getProperty("db_column") + ","
+ vertex3.getProperty("type") + ","
+ vertex3.getProperty("index") + ","
+ vertex3.getProperty("value"));
}
vertex4 = g.addVertex(null);
vertex4.setProperty("db_local_name", "Report Name 1");
vertex4.setProperty("db_schema", "MPS");
vertex4.setProperty("db_column", "amount");
vertex4.setProperty("type", "indivisual_0");
vertex4.setProperty("value", rowObj[3].toString());
vertex4.setProperty("index", i);
vertex1.addEdge("data", vertex4);
logger.debug("vertex1 added");
vertex2.addEdge("data", vertex4);
logger.debug("vertex2 added");
vertex3.addEdge("data", vertex4);
logger.debug("vertex3 added");
i++;
g.commit();
}
Is there anyway to optimize this code?
For completeness, this question was answered in the Aurelius Graphs mailing list:
https://groups.google.com/forum/#!topic/aureliusgraphs/XKT6aokRfFI
Basically:
build/use a real composite index:
mgmt.buildIndex("by_local_name_schema_value", Vertex.class).addKey(db_local_name).addKey(db_schema).addKey(value).buildComposite();
don't call g.commit() after each loop cycle, instead do something
like this: if (++1%10000 == 0) g.commit()
turn on storage.batch-loading if not already doing so
if all you can throw at cassandra is 2G of RAM consider using BerkleyDB. Cassandra prefers 4G of RAM minimum and would probably like "more"
I don't know the nature of your data, but can you pre-sort it and use BatchGraph as described in the Powers of Ten - Part I blog post and in the wiki - Using BatchGraph would prevent you from having to maintain the transaction described in number 2 above.
All is in the question, is there a way to display the € symbol in extjs?
I tried
var euroMoney = function(v) {
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? ',' + ps[1] : ',00',
r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + '.' + '$2');
}
v = whole + sub;
return v + " €";
}
But for euroMoney(1) it returns me
1,00 €
This happens when your text editor saves it the wrong way. Make sure the encoding in your text editor is set to UTF-8 and you should be fine.
I am trying to read all the user attributes in AD.
How to read msExchMailboxSecurityDescriptor attribute in C# ?
I used the following code but I got a cast error. Any suggestions would be welcome.
DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
oSec.SetSecurityDescriptorBinaryForm((byte[])val);
String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All);
return m_Value;
Ok. I was able to figure it out. The code is given below for anyone interested. I wish Microsoft had put out some code samples so that people do not have to break their heads.
SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
String m_Trustee = "";
String m_AccessMask = "";
String m_AceType = "";
String m_ReturnValue="";
foreach (AccessControlEntry ace in (IEnumerable)acl)
{
m_Trustee = m_Trustee + "," + ace.Trustee;
m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
m_AceType = m_AceType + "," +ace.AceType.ToString();
}
m_ReturnValue="Trustee: " + m_Trustee + " " + "AccessMask: " + m_AccessMask + "AceType: " + m_AceType;
return m_ReturnValue