How to remove column with ML.NET ColumnDropper - ml.net

Guys I'm new in machine learning and I'm trying to use Microsoft.ML and in particular Transform part of the framework.
Can you somebody tell me what I'm doing wrong. I cannot remove a column from my dataset?
var loader = new Microsoft.ML.Data.TextLoader(TrainDataPath).CreateFrom<BloodDonateData>(useHeader: true, separator: ',');
int columnsCount = 5;
using (var environment = new TlcEnvironment())
{
Experiment experiment = environment.CreateExperiment();
ILearningPipelineDataStep pipelineDataStep = loader.ApplyStep(null,
experiment) as ILearningPipelineDataStep;
experiment.Compile();
loader.SetInput(environment, experiment);
experiment.Run();
ColumnDropper columnDropper = new ColumnDropper
{
Column = new string[] { "Time" },
Data = pipelineDataStep.Data
};
columnDropper.ApplyStep(pipelineDataStep, experiment);
var data = experiment.GetOutput(columnDropper.Data);
using (var cursor = data.GetRowCursor(a => true))
{
// print data..
}
}

Related

How to add dynamic values to field injections list with custom trigger to camunda properties panel?

I have two questions here
Is it possible to add dynamic lists values to field injection list input ?
Can I create a trigger for this so this can be initiated from any other input selection say a class selection will populate all fields
I was just looking into FieldInjection.js whether that can be extented for the same
Can someone please provide a hint or direction for this ?
Thanks.
For anyone interested in the answer, I was able to achieve the above goal by changing the set function of the Java Class select input as folllowing
few imports
var extensionElementsHelper = require('../../../../helper/ExtensionElementsHelper'),
elementHelper = require('../../../../helper/ElementHelper')
var CAMUNDA_FIELD_EXTENSION_ELEMENT = 'camunda:Field';
function getExtensionFields(bo) {
return bo && extensionElementsHelper.getExtensionElements(bo, CAMUNDA_FIELD_EXTENSION_ELEMENT) || [];
}
then changing the set function to create extension element and push the field values as :
set: function(element, values, node) {
var bo = getBusinessObject(element);
var type = getImplementationType(element);
var attr = getAttribute(type);
var prop = {}
var commands = [];
prop[attr] = values.delegate || '';
var extensionElements = getExtensionFields(bo);
//remove any extension elements existing before
extensionElements.forEach(function(ele){
commands.push(extensionElementsHelper.removeEntry(getBusinessObject(element), element, ele));
});
if(prop[attr] !== ""){
var extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, bo, bpmnFactory);
commands.push(cmdHelper.updateBusinessObject(element, bo, { extensionElements: extensionElements }));
var arrProperties = ["private org.camunda.bpm.engine.delegate.Expression com.cfe.extensions.SampleJavaDelegate.varOne","private org.camunda.bpm.engine.delegate.Expression com.cfe.extensions.SampleJavaDelegate.varTwo"]
var newFieldElem = "";
arrProperties.forEach(function(prop){
var eachProp = {
name:"",
string:"",
expression:""
}
var type = prop.split(" ")[1].split(".").reverse()[0];
var val = prop.split(" ")[2].split(".").reverse()[0];
eachProp.name = val;
if( type == "String"){
eachProp.string = "${" + val +" }"
}else if( type == "Expression"){
eachProp.expression = "${" + val +" }"
}
newFieldElem = elementHelper.createElement(CAMUNDA_FIELD_EXTENSION_ELEMENT, eachProp, extensionElements, bpmnFactory);
commands.push(cmdHelper.addElementsTolist(element, extensionElements, 'values', [ newFieldElem ]));
});
}
commands.push(cmdHelper.updateBusinessObject(element, bo, prop));
return commands;
}
Cheers !.

Updating Location and ShipQty in Acumatica Shipment Lines

I'm having this weird problem in acumatica webservices, I'm updating existing Shipments in acumatica using webservices. My code is supposed to update the Location and ShippedQty but for no reason it updates all the items except the last one. It happens when the Shipment has multiple items. Please help me solve this problem, below is my code and an image of the Shipment screen with the last item not updated.
Thanks.
var commands = new List<Acumatica_LSOne_Integration.SO302000.Command>();
commands.Add(new SO302000.Value { Value = shipmentNbr, LinkedCommand = shipmentSchema.ShipmentSummary.ShipmentNbr });
commands.Add(new SO302000.Value { Value = shipmentType, LinkedCommand = shipmentSchema.ShipmentSummary.Type });
commands.Add(shipmentSchema.DocumentDetails.ShipmentNbr);
commands.Add(shipmentSchema.DocumentDetails.LineNbr);
commands.Add(shipmentSchema.DocumentDetails.InventoryID);
commands.Add(shipmentSchema.DocumentDetails.Warehouse);
commands.Add(shipmentSchema.DocumentDetails.Location);
commands.Add(shipmentSchema.DocumentDetails.OrderedQty);
var soLines = context.Submit(commands.ToArray());
List<Acumatica_LSOne_Integration.SO302000.Command> commandList = new List<Acumatica_LSOne_Integration.SO302000.Command>();
for (int index = 0; index < soLines.Length; index++)
{
string sShipNbr = soLines[index].DocumentDetails.ShipmentNbr.Value;
string sLineNbr = soLines[index].DocumentDetails.LineNbr.Value;
string sInventoryID = soLines[index].DocumentDetails.InventoryID.Value;
string sWarehouse = soLines[index].DocumentDetails.Warehouse.Value;
string sLocation = soLines[index].DocumentDetails.Location.Value;
string sOrderedQty = soLines[index].DocumentDetails.OrderedQty.Value;
commandList.Add(new SO302000.Key
{
ObjectName = shipmentSchema.DocumentDetails.ShipmentNbr.ObjectName,
FieldName = shipmentSchema.DocumentDetails.ShipmentNbr.FieldName,
Value = sShipNbr.Trim(), Commit = true
});
commandList.Add(new SO302000.Key
{
ObjectName = shipmentSchema.DocumentDetails.LineNbr.ObjectName,
FieldName = shipmentSchema.DocumentDetails.LineNbr.FieldName,
Value = sLineNbr.Trim(), Commit = true
});
commandList.Add(new SO302000.Value
{
Value = vLocation.Trim(),
LinkedCommand = shipmentSchema.DocumentDetails.Location
});
commandList.Add(new SO302000.Value { Value = sOrderedQty, LinkedCommand = shipmentSchema.DocumentDetails.ShippedQty,IgnoreError = true, Commit = true });
}
commandList.Add(shipmentSchema.Actions.ConfirmShipmentAction);
context.Submit(commandList.ToArray());
Sample Output:
I guessed that you have allowed negative quantity on your inventory, by default when an item has zero quantity on a particular warehouse the location will set as and a shipped quantity of zero and as I've seen you're code, check this line code
string sLocation = soLines[index].DocumentDetails.Location.Value;
if this soLine retreives a value as I guess this line is the cause why it won't update.
I've actually come up with a solution that works well using the Contract Based Web Services. Below is my sample code:
using (DefaultSoapClient soapClient = new DefaultSoapClient())
{
InitializeWebService(soapClient,sAUser,sAPass,vCompany,vBranchID);
Shipment shipmentToBeFound = new Shipment
{
Type = new StringSearch { Value = shipmentType },
ShipmentNbr = new StringSearch { Value = shipmentNbr },
};
Shipment shipment = (Shipment)soapClient.Get(shipmentToBeFound);
int iLineNbr = Int32.Parse(sLineNbr);
ShipmentDetail shipmentLine = shipment.Details.Single(
orderLineToBeUpdated =>
orderLineToBeUpdated.LineNbr.Value == iLineNbr);
shipmentLine.LocationID = new StringValue { Value = vLocation.Trim() };
shipmentLine.ShippedQty = new DecimalValue { Value = decimal.Parse(sOrderedQty) };
shipment = (Shipment)soapClient.Put(shipment);
soapClient.Logout();
}

Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

Can someone help me delete a SalesOrderLine from a SalesOrder?
I'm using the GP WS Native Endpoint
My code executes without an error.
However, after updating the SalesOrder, the line I removed still remains.
var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};
var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);
var newLines = salesOrder.Lines.Where(l => l.Key.LineSequenceNumber != lineItemSequence).ToArray();
salesOrder.Lines = newLines;
var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);
this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);
Thank you for any help,
Karl
Microsoft Dynamics GP Web Service has poor documentation and examples.
Do delete a sales order line, you retrieve the order, locate the line to delete and set the sales order line property, DeleteOnUpdate to true, and then save the order.
Updated code below:
var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};
var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);
var target= salesOrder.Lines.FirstOrDefault(l => l.Key.LineSequenceNumber == lineItemSequence);
if (target != null) {
target.DeleteOnUpdate = true;
}
var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);
this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);

How to use boosting in solrnet while using default query?

I am using SolrNet to do query on my default search field and not on any specific field. How can I use Boost on a specific field in that case? Below is the code snippet.
List filter = BuildQuerySingleLine(arrParams);
var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
{
FilterQueries = filter,
SpellCheck = new SpellCheckingParameters { Collate = true },
OrderBy = new[] { new SortOrder("score", Order.DESC), SortOrder.Parse("score DESC") },
StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
Rows = parameters.NumberOfRows
});
At last I found the solution to this problem. For this I have used dismax request handler and passed the qf param value through SOLRNET.
With this you can pass the dynamic boost value to the SOLR query, on different fields.
var extraParams = new Dictionary<string, string> { { "qt", "dismax" }, { "qf", "fieldName^1 FieldName^0.6" } };
var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
{
StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
Rows = parameters.NumberOfRows,
},
ExtraParams = extraParams
});
According to this document: Querying and The DisMax Query Parser
var extraParams = new List<KeyValuePair<string, string>>();
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeQuery^10"));
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeOtherQuery^10"));
var options new new QueryOptions();
options.ExtraParams = extraParams; //Since my List implements the right interface
solr.Query(myQuery, options)
the bq parameter should be used to boost the Query. #Abhijit Guha has an excellent answer, to use the same idea on the Field: qf (Query fields with optional boosts)
QueryOptions options = new QueryOptions
{
ExtraParams = new KeyValuePair<string, string>[]
{
new KeyValuePair<string,string>("qt", "dismax"),
new KeyValuePair<string,string>("qf", "title^1")
},
Rows = 10,
Start = 0
};
Thank You!

Listing Activities via Web Services

I'm trying to reproduce the Activities page in Microsoft CRM 4.0 via web services. I can retrieve a list of activities, and I believe I need to use ActivityPointers to retrieve the entities but have so far been unsuccessful. Would I need to loop through every single entity returned from the first query to retrieve the ActivityPointer for it? And if so, how would I then get the "Regarding" field or Subject of the activity (eg: email).
The code to retrieve the activities is:
var svc = GetCrmService();
var cols = new ColumnSet();
cols.Attributes = new[] { "activityid", "addressused", "scheduledstart", "scheduledend", "partyid", "activitypartyid", "participationtypemask", "ownerid" };
var query = new QueryExpression();
query.EntityName = EntityName.activityparty.ToString();
query.ColumnSet = cols;
LinkEntity link = new LinkEntity();
//link.LinkCriteria = filter;
link.LinkFromEntityName = EntityName.activitypointer.ToString();
link.LinkFromAttributeName = "activityid";
link.LinkToEntityName = EntityName.activityparty.ToString();
link.LinkToAttributeName = "activityid";
query.LinkEntities = new[] {link};
var activities = svc.RetrieveMultiple(query);
var entities = new List<ICWebServices.activityparty>();
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse) svc.Execute(request);
//var pointers = new List<activitypointer>();
foreach (activityparty c in activities.BusinessEntities)
{
entities.Add(((activityparty)c));
//the entities don't seem to contain a link to the email which they came from
}
Not sure if I understand your problem, but the field "activityid" in the activitypointer object is the same activityid as the underlying activity (email, task, phonecall, etc). The regardingobjectid is the link to the regarding entity.
Heres what you need to get the equivalent of the Activities page
ColumnSet cols = new ColumnSet()
{
Attributes = new string[] { "subject", "regardingobjectid", "regardingobjectidname", "regardingobjectidtypecode", "activitytypecodename", "createdon", "scheduledstart", "scheduledend" }
};
ConditionExpression condition = new ConditionExpression()
{
AttributeName = "ownerid",
Operator = ConditionOperator.Equal,
Values = new object[] { CurrentUser.systemuserid.Value } //CurrentUser is an systemuser object that represents the current user (WhoAmIRequest)
};
FilterExpression filter = new FilterExpression()
{
Conditions = new ConditionExpression[] { condition },
FilterOperator = LogicalOperator.And
};
QueryExpression query = new QueryExpression()
{
EntityName = EntityName.activitypointer.ToString(),
ColumnSet = cols,
Criteria = filter
};
BusinessEntityCollection activities = svc.RetrieveMultiple(query);
foreach (activitypointer activity in activities)
{
//do something with the activity
//or get the email object
email originalEmail = (email)svc.Retrieve(EntityName.email.ToString(), activity.activityid.Value, new AllColumns());
}