I would like to traverse from a vertex, only following edges that match a particular expression (example: friendsWith.type="bestFriend"). How do I do this?
Furthermore, I have to run this operation for a bunch of vertices. Is it possible to keep things organized by the "head" of the traversals? Ideally the return would be:
[[start1, [list of all the vertices during traversal], [start2, [...]],...]
I tried with this graph
I used this javascript function with the parameter rid
var g=orient.getGraph();
var nodes = [];
var previous=[];
var currently=[];
var b=g.command("sql","select from " + rid);
if(b.length>0){
var vertex=b[0];
previous.push(vertex);
nodes.push(vertex);
do{
for(i=0;i<previous.length;i++){
var vertexOut=previous[i];
var edges=g.command("sql","select expand(outE('friendsWith')) from "+ vertexOut.getId());
for(s=0;s<edges.length;s++){
var edge=edges[s];
var type= edge.getProperty("type");
if(type=="bestFriend"){
var vertices=g.command("sql","select expand(inV('friendsWith')) from "+ edge.getId());
var vertex=vertices[0];
var found=false;
for(k=0;k<nodes.length;k++){
var id=nodes[i].getId();
var id_v=vertex.getId()
if(id==id_v){
found=true;
break;
}
}
if(found==false){
currently.push(vertex);
nodes.push(vertex);
}
}
}
}
change();
}while(previous.length>0);
return nodes;
}
function change(){
previous=[];
for (indice=0;indice<currently.length;indice++)
previous.push(currently[indice]);
currently=[];
}
and with select expand(node) from (select myFunction("#9:0") as node) I got
Hope it helps.
try this:
select outV().name as start, inV().name as end from(traverse * from friendsWith while type = "bestFriend")
you can do it even without traverse.
Hope it helps.
Regards.
Related
I need to take data from a basic excel form and paste it on a data table as many times as one of the cells form the form says.
This is the form:
Form
I've tried this:
function COPIARPEGAR() {
var Libro = SpreadsheetApp.getActiveSpreadsheet();
var Form = Libro.getSheetByName("Form")
var CON = Form.getRange('J18').getValue();
var Disciplina = Form.getRange('J20').getValue();
var Masculino = Form.getRange('L22').getValue();
var TituloMasculino = Form.getRange('L20').getValue();
var Femenino = Form.getRange('N22').getValue();
var TituloFemenino = Form.getRange('N20').getValue();
var BBDD = Libro.getSheetByName("BBDD2");
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length
for(var filamasc=UltimaFila+1;filamasc<=Masculino+1;filamasc++) {
BBDD.getRange(filamasc,1).setValue(Disciplina)
BBDD.getRange(filamasc,2).setValue(CON)
BBDD.getRange(filamasc,3).setValue(TituloMasculino)
for(var filafem=UltimaFila+1;filafem<=Femenino+1;filafem++) {
BBDD.getRange(filafem,1).setValue(Disciplina)
BBDD.getRange(filafem,2).setValue(CON)
BBDD.getRange(filafem,3).setValue(TituloFemenino)
}
Logger.log(UltimaFila);
Logger.log(CON);
Logger.log(Disciplina)
}
And as result I always get the smaller number overwrited by the largest number like this:
result
Thanks for yur help!
Your loops are the issue in that you aren't starting at the same rows. Consider running your code in debug mode so you can see your variables value on the right hand part of the screen (such as UltimaFila = 1). I looked at your code, and I think this would work with modifications, but again look at your variables on the right side of your code, and run in debug mode.
function COPIARPEGAR() {
var Libro = SpreadsheetApp.getActiveSpreadsheet();
var Form = Libro.getSheetByName("Form")
var CON = Form.getRange('J18').getValue();
var Disciplina = Form.getRange('J20').getValue();
var Masculino = Form.getRange('L22').getValue();
var TituloMasculino = Form.getRange('L20').getValue();
var Femenino = Form.getRange('N22').getValue();
var TituloFemenino = Form.getRange('N20').getValue();
var BBDD = Libro.getSheetByName("BBDD2");
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length;
//Updated the ending point
for (var filamasc = UltimaFila + 1; filamasc <= Masculino + 1 + UltimaFila; filamasc++) {
BBDD.getRange(filamasc, 1).setValue(Disciplina)
BBDD.getRange(filamasc, 2).setValue(CON)
BBDD.getRange(filamasc, 3).setValue(TituloMasculino)
}
//See the starting points change
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length
//Updated the ending point
for (var filafem = UltimaFila + 1; filafem <= Femenino + 1 + UltimaFila; filafem++) {
BBDD.getRange(filafem, 1).setValue(Disciplina)
BBDD.getRange(filafem, 2).setValue(CON)
BBDD.getRange(filafem, 3).setValue(TituloFemenino)
}
Logger.log(UltimaFila);
Logger.log(CON);
Logger.log(Disciplina)
}
How To Debug Your Code
I’ve got multiple variables with the same name but a different number on the end like this:
MyVar1, MyVar2, MyVar3, MyVar4
and they are either true or false
How do I write this correctly?
For index in Range(1...4){
if (“MyVar” + index) == true{
print(“:)”)
}
}
didnt tries the solution but according to this post: https://stackoverflow.com/a/45622489/5464805 you can do this:
Edit: I read that your variables are Booleans
for i in 0...4 {
if let var = myObject.value(forKey: "MyVar\(i)") as Bool,
var { // If var is successfully cast and true it enters the statement
print(var)
}
}
HOWEVER
All the other solutions above or below are still correct. This is something you dont usually do in Swift in general unless you must do so.
You should either rewrite your model and give a proper name to each variables, that you will later put into an array such as...
class MyObject {
var MyVar1: Bool // To Rename
var MyVar2: Bool // To Rename
var MyVar3: Bool // To Rename
var MyVars: [Bool] {
get { return [MyVar1, MyVar2, MyVar3] }
}
}
Or you completely get rid of these variable and create an Array directly
class MyObject {
// var MyVar1: Bool // To Delete
// var MyVar2: Bool // To Delete
// var MyVar3: Bool // To Delete
var MyVars: [Bool]
}
and you set the Array / Dictionnary in accordance to your needs
You are trying to get a sum of String ("MyVar") and Int ("index") and compare that sum with Bool (true)
It would be more safety to store all your variables in an array like that
let myVars = [MyVar1, MyVar2, MyVar3, MyVar4]
Then you can iterate throught the array:
for i in myVars {
if i {
print(i)
}
}
You can't create a variable from concatenation at runtime , you need to have an array of bool like this
var arr = [false,true,true,false] // var1 , var2 , var3 , var4
for item in arr {
if item {
}
}
I've a ForEach loop in my var body: some View but the var isn't recognized after the if loop. Is there a way to fix this?
I've tried to remove the if loop and set it above the body item. But then I get some error that te isOldDate var is used before Self is available.
if self.Bol{
let OldDateType = self.OldDate.asDate
}else{
var OldDateType = isNewDay
}
var isOldDate = (OldDateType, formatter: ContentView.self.Day)
The expected result is that var isOldDate should be recognized
Try to write the if/else as
let oldDateType = self.Bol ? self.OldDate.asDate : isNewDay
I'm trying to get the number of members of some Facebook groups. I tried to play with the Facebook Graph API but it does not work:
function facebook(url) {
var jsondata = UrlFetchApp.fetch('http://graph.facebook.com/http://www.facebook.com/groups/449592401822610/?ref=br_rs');
var object = Utilities.jsonParse(jsondata.getContentText());
return object.shares;
}
Is it possible to do that?
Thanks for your help
[UPDATE]
Sometimes I don't have the ID of the group. I wrote this to solve the issue but it does not work...
function facebook(group) {
if (isNaN(group) == true) {
var jsondata1 = UrlFetchApp.fetch('https://graph.facebook.com/search?q='+group+'&type=group&access_token={my token}');
var object1 = Utilities.jsonParse(jsondata1.getContentText());
var id = object1.data.id;
var jsondata2 = UrlFetchApp.fetch('https://graph.facebook.com/v2.5/'+id+'/members?summary=true&access_token={my token}');
var object2 = Utilities.jsonParse(jsondata2.getContentText());
return object2.summary.total_count;
}
else {
var jsondata = UrlFetchApp.fetch('https://graph.facebook.com/v2.5/'+group+'/members?summary=true&access_token={my token}');
var object = Utilities.jsonParse(jsondata.getContentText());
return object.summary.total_count;
}
}
Any idea?
Using Graph API
https://graph.facebook.com/v2.5/449592401822610/members?summary=true&access_token={user-access_token}
you will get response like this if it is closed group
{
"data": [
],
"summary": {
"total_count": 4113
}
}
and if it is public group you will also receive members detail in data section
Good Luck
NOTE: this will only return count <5000 member. If your group is near 5000 or more than 5000 it will return 4897, 4756, or some other "random" number, but will never return more than 5000.
It looks like the URL in your code is wrong, I'm guessing it should be
http://graph.facebook.com/groups/449592401822610/?ref=br_rs
i couldnt do aautocopmlete edit box. i want to take names from another database. i wrote my code to typeahead's value list. but it dont work. i am using same server but different database.anybody help me ? here is my code:
//Getting the view containing a document for each of the employees
var searchView:NotesView = session.getDatabase("servername","test/application name.nsf")
.getView("viewname");
// Creating a Lotus Notes search query. Notice the reference to lupkey!
var query = "(FIELD Ad Soyad CONTAINS *" + lupkey +"*)";
// Creating an array to store hits in
var searchOutput:Array = ["å","åå"];
// Doing the actual search
var hits = searchView.FTSearch(query);
var entries = searchView.getAllEntries();
var entry = entries.getFirstEntry();
//Sort the array manually, since Notes doesn't want to sort them alphabetically
for (i=0; i<hits; i++) {
searchOutput.push(entry.getColumnValues()[0]);
entry = entries.getNextEntry();
}
searchOutput.sort();
// Build the resulting output HTML code
var result = "<ul><li><span class='informal'>Suggestions:</span></li></ul>";
var limit = Math.min(hits,20);
for (j=0; j<limit; j++) {
var name = searchOutput[j].toString();
var start = name.indexOfIgnoreCase(lupkey)
var stop = start + lupkey.length;
//Make the matching part of the name bold
name = name.insert("</b>",stop).insert("<b>",start);
result += "<li>" + name + "</li>";
}
result += "</ul>";
return result;
There are plenty of issues with your code:
the query can't return any result since your field has a space in it
Do you really need an FTSearch to return values and not a sorted view?
the typeahead -as the name suggest- presents values that match left to right and not somewhere substring. If you need that you need to roll your own typeahead function using Ajax
The typeahead function doesn't take a parameter, so your lupkey doesn't go anywhere. The function needs to return all values and XPages will do the matching
Instead of copying one by one into an array for sorting, copy the returning Vector() into a TreeSet(). This is one line, sorts it and removes duplicates
To get it working check this example based on dojo, previously asked here. You will need the REST control
i do it like that
var directoryTypeahead = function (searchValue:string) {
// update the following line to point to your real directory
//var directory:NotesDatabase = session.getDatabase(database.getServer(), "names.nsf");
var directory:NotesDatabase = session.getDatabase(database.getServer(), "org/test.nsf");
var allUsers:NotesView = directory.getView("SVFHP2");
var matches = {};
var includeForm = {
Person: true,
Group: true
}
searchValue = searchValue.replace("I","i")
var matchingEntries:NotesViewEntryCollection = allUsers.getAllEntriesByKey(searchValue, false);
var entry:NotesViewEntry = matchingEntries.getFirstEntry();
var resultCount:int = 0;
while (entry != null) {
var matchDoc:NotesDocument = entry.getDocument();
var matchType:string = matchDoc.getItemValueString("Form");
//if (includeForm[matchType]) { // ignore if not person or group
var fullName:string = matchDoc.getItemValue("Name").elementAt(0) + " " + matchDoc.getItemValue("Title").elementAt(0);
if (!(matches[fullName])) { // skip if already stored
resultCount++;
var matchName:NotesName = session.createName(fullName);
matches[fullName] = {
cn: matchName.getCommon(),
photo: matchDoc.getItemValueString("Photo"),
job: matchDoc.getItemValueString("sum"),
email: matchDoc.getItemValueString("email"),
}
}
// }
/*if (resultCount > 15) {
entry = null; // limit the results to first 10 found
}
else {*/
entry = matchingEntries.getNextEntry(entry);
//}
};
}