//using ArcGIS.Core.Data.Knowledge.Extensions;
//var results = kg.ComputeCentrality(...);
var count_entities = results.RawUids.Count();
var score_len = results.Scores.RawScores.Length;
//Find the max and min score for each measure w/out
//using LINQ or sorting
for (int m = 0; m < results.Scores.Measures.Length; m++)
{
//index into the scores array for the current measure
var start_idx = count_entities * m;
var end_idx = start_idx + count_entities;
double max_score = double.MinValue;
double min_score = double.MaxValue;
List<object> max_uids = new List<object>();
List<object> min_uids = new List<object>();
for (int i = 0, s = start_idx; s < end_idx; i++, s++)
{
var score = results.Scores.RawScores[s];
//max
if (score > max_score)
{
max_score = score;
max_uids.Clear();
max_uids.Add(results.RawUids[i]);
}
else if (score == max_score)
{
//Collect all uids with the max score
max_uids.Add(results.RawUids[i]);
}
//min
if (score < min_score)
{
min_score = score;
min_uids.Clear();
min_uids.Add(results.RawUids[i]);
}
else if (score == min_score)
{
//Collect all uids with the min score
min_uids.Add(results.RawUids[i]);
}
}
//TODO - use the max and min scores and uids for
//the current measure "measures[m]"
//max_score, max_uids
//min_score, min_uids
}
//using ArcGIS.Core.Data.Knowledge.Extensions;
//var results = kg.ComputeCentrality(...);
var count_entities = results.RawUids.Count();
var score_len = results.Scores.RawScores.Length;
//Find the max and min score for each measure using LINQ
for (int m = 0; m < results.Scores.Measures.Length; m++)
{
//index into the scores array for the current measure
var start_idx = count_entities * m;
var end_idx = start_idx + count_entities;
//Get the scores for the specified measure
var scores = Enumerable.Range(start_idx, count_entities)
.Select(i => results.Scores.RawScores[i]).ToArray();
//max + min
var max_score = scores.Max();
var min_score = scores.Min();
//uids with the max score
var max_uids = Enumerable.Range(0, count_entities)
.Where(i => scores[i] == max_score)
.Select(i => results.RawUids[i])
.ToList();
//uids with the min score
var min_uids = Enumerable.Range(0, count_entities)
.Where(i => scores[i] == min_score)
.Select(i => results.RawUids[i])
.ToList();
//TODO - use the max and min scores and uids for
//the current measure "measures[m]"
//max_score, max_uids
//min_score, min_uids
}
//using ArcGIS.Core.Data.Knowledge.Extensions;
//Note: logic uses the following custom class:
//
//public class KG_Score_Value {
// public KG_Score_Value(double score, int uid_idx) {
// Score = score;
// Uid_idx = uid_idx;
// }
//
// public double Score { get; set; }
// public int Uid_idx { get; set; }
//}
//var results = kg.ComputeCentrality(...);
var count_entities = results.RawUids.Count();
var score_len = results.Scores.RawScores.Length;
//Find the top and bottom "n" scores for each measure
for (int m = 0; m < results.Scores.Measures.Length; m++)
{
//index into the scores array for the current measure
var start_idx = count_entities * m;
var end_idx = start_idx + count_entities;
//Get the scores for the specified measure
var scores = Enumerable.Range(start_idx, count_entities)
.Select(i => results.Scores.RawScores[i]).ToArray();
//use "KG_Score_Value" to hold the score and uid index
var uid_idx = 0;
var kg_score_vals = Enumerable.Range(start_idx, count_entities)
.Select(i => new KG_Score_Value(results.Scores.RawScores[i], uid_idx++))
.OrderByDescending(k => k.Score)
.ToArray();
//get up to the top or bottom N scores
if (n > kg_score_vals.Length)
n = kg_score_vals.Length;
//get the top N scores and uids - largest first
var top_n = kg_score_vals.Take(n).ToList();
//get the bottom N scores and uids - smallest first
var bottom_n = kg_score_vals.TakeLast(n)
.Reverse().ToList();
foreach (var kg_score in top_n)
{
//TODO - use top "n" scores
var score = kg_score.Score;
var uid = results.RawUids[kg_score.Uid_idx];
//...use it
}
foreach (var kg_score in bottom_n)
{
//TODO - use bottom "n" scores
var score = kg_score.Score;
var uid = results.RawUids[kg_score.Uid_idx];
//...use it
}
}
Target Platforms: Windows 11, Windows 10