Reputation: 397
I'm using the code on https://learn.microsoft.com/en-us/azure/cognitive-services/anomaly-detector/quickstarts/client-libraries-multivariate?pivots=programming-language-csharp I have created a csv file in a blob storage account. The zipped and unzipped copies have both been uploaded.
This is the url for my datasource with the private bits as xxx.
string datasource = "https://xx.blob.core.windows.net/testdirectory?sp=r&st=2021-07-21T14:10:15Z&se=2021-07-21T22:10:15Z&sip=xx&spr=https&sv=2020-08-04&sr=c&sig=xxx";
What does this code do and why is always returning a count of zero?
private async Task<int> getModelNumberAsync(AnomalyDetectorClient client, bool delete = false)
{
int count = 0;
AsyncPageable<ModelSnapshot> model_list = client.ListMultivariateModelAsync(0, 10000);
await foreach (ModelSnapshot x in model_list)
{
count += 1;
Console.WriteLine(String.Format("model_id: {0}, createdTime: {1}, lastUpdateTime: {2}.",
x.ModelId, x.CreatedTime, x.LastUpdatedTime));
if (delete & count < 4)
{
await client.DeleteMultivariateModelAsync(x.ModelId).ConfigureAwait(false);
}
}
return count;
}
Upvotes: 0
Views: 145
Reputation: 131
What does this code (getModelNumberAsync function) do?
It lists models that exist already (from previously trained models for example) for a given client.
Also, if delete parameter has been set to true, it deletes the 3 most recent models.
I personally think (I could be wrong) that this sample has a bug. I think that intent of the sample's author was to delete all older models except for the most recent 4 (so, it should have been count > 4). In any case, the delete flag is never set to true in the sample code. So, its a moot point.
Why is it always returning a count of zero?
This indicates that no model has been created yet. This is most likely because you have not yet attempted to train a model. Check to see if you are calling the trainAsync function in the sample code. Even if your training fails (because the csv files were not the expected format etc), a model will be created with a Status of "Failed" and at that point count should be > zero.
For example, when I tried the sample, my training failed (because of unrelated reasons - my data was not in the expected format) but getModelNumberAsync listed all previous models that the client knew of (and the count was 5). I added the "status: {3}" to the console log line. It was not in the sample code.
Upvotes: 1