I am having an issue with the creation of a Wordcloud with Highcharts 7.1.2 with C# and .NET.
I can create the wordcloud just fine, but I can't set the weight of the words.
The piece of code below is what I currently have, as you can see I am trying to use the Labelrank as a mean to set the weight. I cannot find an example of the wordcloud in c#, but I found some in JS and they always set the weight of each word.
List<Series> seriesList = new List<Series>();
List<WordcloudSeriesData> newWordcloudSeriesDataList = new List<WordcloudSeriesData>();
foreach (var data in datas)
{
newWordcloudSeriesDataList.Add(new WordcloudSeriesData
{
Name = data.Name,
Labelrank = data.Rank
});
}
seriesList.Add(new WordcloudSeries
{
Data = newWordcloudSeriesDataList,
Rotation = new WordcloudSeriesRotation
{
From = 0,
To = 0,
Orientations = 1
}
});
PS: I found a workaround.
When you create the json before sending it to the front, use
chartinfo = chartinfo.Replace("labelrank", "weight");
where chartinfo is the json.
Related
I'm trying to create my first Xamarin.Forms mobile app with a map and pins, so please bear with me.
I'm trying to add pins to the map. I use this code to add one pin:
map = new Map {
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
map.MoveToRegion (MapSpan.FromCenterAndRadius (
new Position (36.9628066,-122.0194722), Distance.FromMiles (3)));
var position = new Position(36.9628066,-122.0194722);
var pin = new Pin {
Type = PinType.Place,
Position = position,
Label = "Santa Cruz",
Address = "custom detail info"
};
map.Pins.Add(pin);
Now, instead of adding just one pin, I'd like to add several pins from a tsql table.
So I created a WCF service that returns a list of coordinates. One returns a json and the other returns a datatable:
public DataTable ToEraseGetCoordinates()
{
string sqlQuery = "select lat,lon from MyStores";
string connString = GetConnString();
SqlDatabase sqlDatabase = new SqlDatabase(connString);
DataSet result = sqlDatabase.ExecuteDataSet(CommandType.Text, sqlQuery);
return result.Tables[0];
}
public System.IO.Stream ToEraseGetCoordinatesJson()
{
string sqlQuery = "select lat,lon from MyStores";
string connString = GetConnString();
SqlDatabase sqlDatabase = new SqlDatabase(connString);
DataSet result = sqlDatabase.ExecuteDataSet(CommandType.Text, sqlQuery);
return ConvertToJson(result.Tables[0]);
}
I invoke the WCF like so: http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinates (for an xml representation of the datatable)
For the JSON: http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinatesJson, which returns this:
{"lat":25.7616,"lon":-80.1917},{"lat": 28.5383,"lon":-81.3792}
My question is: what do I next so that my Xamarin.Form reads this?
Regardless of the return type, I don't know how Xamarin will consume the WCF and draw the pins.
This earthquake map sample does basically what you want (it's a bit old, sadly).
Basically you want to download your Json (eg in this class)
// your http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinatesJson would go here
var response = await client.GetAsync("earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt");
var earthquakesJson = response.Content.ReadAsStringAsync().Result;
then you need to convert the Json - but you said you've already done that
var rootobject = JsonConvert.DeserializeObject<Rootobject>(earthquakesJson);
lastly just create and add the pins to the map
var earthquakes = await webSvc.GetEarthquakesAsync();
Xamarin.Forms.Device.BeginInvokeOnMainThread( () => {
Debug.WriteLine("found " + earthquakeString.Length + " earthquakes");
label.Text = earthquakeString.Length + " earthquakes";
foreach (var earthquake in earthquakes)
{
var p = new Pin();
p.Position = new Position(earthquake.lat, earthquake.lng);
p.Label = "Magnitude: " + earthquake.magnitude;
m.Pins.Add(p);
}
});
Originally the pins weren't able to be databound, which is why it loops through to add them. Not sure if the ability to databind pings has been added to Xamarin.Forms since.
You'll probably want to keep track of the lat/longs so you can calculate a new region to set the maps view, to default to showing all the pins you added...
See the Maps docs and maps custom renderers for more info.
I'm trying to write a script score function which boosts items who belong to just one category.
new ScriptScoreFunction
{
Script = new ScriptQuery
{
Lang = "painless",
Source = "doc['categories'].values.length == 1",
},
Weight = 10
}
The code below does not seem to work. I'm getting a "bad response code" from the API. What am I doing wrong?
solved by using this as the source of my script:
if (doc['categories.slug'].values.length == 1) { return 1; } return 0;
NOTE: 'slug' is a property of the property 'category'.
I'm trying to query the search API of Rally, here is my c# code:
var searchRequest = new Request()
{
ArtifactName = "search",
Limit = 25,
Project = "/project/" + CurrentProject,
ProjectScopeDown = true,
ProjectScopeUp = true,
PageSize = 25,
Fetch = new List<string>() { "true" }
};
searchRequest.AddParameter("keywords", "foo");
QueryResult queryTaskResult = api.Query(searchRequest);
this works as expected and returns result, however i want to pass a parameter of compact=true, which will return slightly different data (mainly a standard web link to the item).
var searchRequest = new Request()
{
ArtifactName = "search",
Limit = 25,
Project = "/project/" + CurrentProject,
ProjectScopeDown = true,
ProjectScopeUp = true,
PageSize = 25,
Fetch = new List<string>() { "true" }
};
searchRequest.AddParameter("keywords", "foo");
///this is the new item
searchRequest.AddParameter("compact", "true");
QueryResult queryTaskResult = api.Query(searchRequest);
However when i fire this request I get the following error
Rally.RestApi.Json.DynamicJsonObject' does not contain a definition for 'Errors'
However when I try to do this request in the browser it works fine.
Any help as to what I'm doing wrong would be greatly appreciated!
Why do you want to do this?
What I want to do is build up a link to the WEB view of the object, eg:
https://rally1.rallydev.com/#/{CurrentProject}d/detail/{ObjectType}/{ObjectId}
I already know the CurrentProject, I need to know the ObjectType and the ObjectId
I have found, when i pass compact=true, the _ref provides this, '/defect/1234567' but this throws an exception.
If I do not pass compact=true, the _ref returns the API reference 'https://rally1.rallydev.com/slm/webservice/v2.x/defect/1234567'
Unfortunately the compact functionality was added to WSAPI after the .NET toolkit was created and we've never updated it to support it.
I filed a github issue here: https://github.com/RallyTools/RallyRestToolkitFor.NET/issues/37
compact=true was mainly a performance optimization to reduce the size of responses in large result sets.
Other than performance is there a reason you'd like to use it?
This is pretty general, but I'm having a hell of a time figuring out how to consume some of the more complicated Sabre APIs.
I have built working .NET proxy classes in C# using the WSDL for the basic APIs (CreateSession, CloseSession) but for the more complicated APIs I have a really hard time parsing out the complicated XML schema to figure out which methods to call in my program.
Are there any other .NET resources/examples out there that aren't wrapped up in MVC like the code example that Sabre posted on GitHub?
I'm trying to figure out how to use APIs like OTA_AirPriceLLSRQ and TravelItineraryReadRQ.
Thanks in advance for any help!
As I mentioned on the comments, you should not focus on the actual MVC wrapping, as you'll be mainly putting stuff in the Model, or actually you'll put this somewhere else and consume it in the model.
Anyway, just for you to have as example, here's a VERY generic BFM (BargianFinderMax) class. With this approach it's required to create an instance, and after calling the Execute method it stores the response in the instance.
I hope it helps.
using BargainFinderMaxRQv310Srvc;
using System;
using System.IO;
namespace ServicesMethods
{
public class BFM_v310
{
private BargainFinderMaxService service;
private OTA_AirLowFareSearchRQ request;
public OTA_AirLowFareSearchRS response;
public BFM_v310(string token, string pcc, string convId, string endpoint)
{
//MessageHeader
MessageHeader mHeader = new MessageHeader();
PartyId[] pId = { new PartyId() };
pId[0].Value = "SWS";
From from = new From();
from.PartyId = pId;
To to = new To();
to.PartyId = pId;
mHeader.Action = "BargainFinderMaxRQ";
mHeader.Service = new Service()
{
Value = mHeader.Action
};
mHeader.ConversationId = convId;
mHeader.CPAId = pcc;
mHeader.From = from;
mHeader.To = to;
mHeader.MessageData = new MessageData()
{
Timestamp = DateTime.UtcNow.ToString()
};
//Security
Security security = new Security();
security.BinarySecurityToken = token;
//Service
service = new BargainFinderMaxService();
service.MessageHeaderValue = mHeader;
service.SecurityValue = security;
service.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11;
service.Url = endpoint;
createRequest(pcc);
}
private void createRequest(string pcc)
{
request = new BargainFinderMaxRQv310Srvc.OTA_AirLowFareSearchRQ();
request.AvailableFlightsOnly = true;
request.Version = "3.1.0";
request.POS = new SourceType[1];
SourceType source = new SourceType();
source.PseudoCityCode = pcc;
source.RequestorID = new UniqueID_Type();
source.RequestorID.ID = "1";
source.RequestorID.Type = "1";
source.RequestorID.CompanyName = new CompanyNameType();
source.RequestorID.CompanyName.Code = "TN";
source.RequestorID.CompanyName.CodeContext = "Context";
request.POS[0] = source;
OTA_AirLowFareSearchRQOriginDestinationInformation originDestination = new OTA_AirLowFareSearchRQOriginDestinationInformation();
originDestination.OriginLocation = new OriginDestinationInformationTypeOriginLocation();
originDestination.OriginLocation.LocationCode = "BCN";
originDestination.DestinationLocation = new OriginDestinationInformationTypeDestinationLocation();
originDestination.DestinationLocation.LocationCode = "MAD";
originDestination.ItemElementName = ItemChoiceType.DepartureDateTime;
originDestination.Item = "2017-09-10T12:00:00";
originDestination.RPH = "1";
request.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[1] { originDestination };
request.TravelerInfoSummary = new TravelerInfoSummaryType()
{
AirTravelerAvail = new TravelerInformationType[1]
};
request.TravelerInfoSummary.AirTravelerAvail[0] = new TravelerInformationType()
{
PassengerTypeQuantity = new PassengerTypeQuantityType[1]
};
PassengerTypeQuantityType passenger = new PassengerTypeQuantityType()
{
Quantity = "1",
Code = "ADT"
};
request.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[0] = passenger;
request.TravelerInfoSummary.PriceRequestInformation = new PriceRequestInformationType();
request.TravelerInfoSummary.PriceRequestInformation.CurrencyCode = "USD";
//PriceRequestInformationTypeNegotiatedFareCode nego = new PriceRequestInformationTypeNegotiatedFareCode();
//nego.Code = "ABC";
//request.TravelerInfoSummary.PriceRequestInformation.Items = new object[1] { nego };
request.TPA_Extensions = new OTA_AirLowFareSearchRQTPA_Extensions();
request.TPA_Extensions.IntelliSellTransaction = new TransactionType();
request.TPA_Extensions.IntelliSellTransaction.RequestType = new TransactionTypeRequestType();
request.TPA_Extensions.IntelliSellTransaction.RequestType.Name = "50ITIN";
}
public bool Execute()
{
response = service.BargainFinderMaxRQ(request);
return response.PricedItinCount > 0;
}
}
}
My advice is you should add separate models which are built based on Sabre models, and which flatten the whole structure.
For example, TravelItineraryReadRS is a quite complicated document. Using it properties in your program is a real "pain", because every time you need to remember the whole path that leads to to specific information (like, "what is passenger type for PersonName of NameNumber 01.01?").
I suggest you have dedicated model (let's name it Reservation), which have all information that you will need later in your application, extracted from TravelItineraryReadRs.
In order to achieve this you need a dedicated converter which will make convert TravelItineraryReadRs model into Reservation model. Now, inside Reservation model you could have list of Passenger models, which have in on place all important information (NameNumber, PassengerType, SSR codes, etc).
This improves readability and as a bonus you decouple your application from Sabre (imagine, one day someone asks "can we switch from Sabre to Amadeus?" - if you use dedicated models the answer is "yes". If you don't have, then the answer is "probably yes, but it will take 6-9 months).
I want a treeview of dates with year, month and days. I will be using $.ajax to retrieve webservice json data. That bit is easy, but not sure how the json data should be constructed for the jquery treeview to work.
I am using http://jquery.bassistance.de/treeview/demo/ (not used before) in creating my treeview.
I've not used bassistance but have used jstree which has good documentation and examples
This link may also be helpful: http://www.jstree.com/documentation/json_data
An example of the type of json sent down might be
new object[]{
new {
attr = new {id = "node1"},
state = "closed",
data = new {
title = "Title1",
icon = "ico-database"
}
},
new {
attr = new {id = "node2"},
state = "closed",
data = new {
title = "Title2",
icon = "ico-database"
}
}
};