Skip to content

Commit

Permalink
Merge pull request #358 from cmu-sei/v8
Browse files Browse the repository at this point in the history
V8
  • Loading branch information
sei-dupdyke authored May 28, 2024
2 parents fb687da + 36fd23b commit 8865ee5
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 439 deletions.
163 changes: 83 additions & 80 deletions src/Ghosts.Api/Areas/Animator/Controllers/ViewSocialController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,47 @@ public ViewSocialController()
[HttpGet]
public IActionResult Index()
{
ViewBag.IsEnabled = this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled;
if (!this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled)
{
return View();
}

var path = SocialGraphJob.GetSocialGraphFile();
if (!System.IO.File.Exists(path))
{
ViewBag.IsEnabled = false;
return View();
}

var graphs = JsonConvert.DeserializeObject<List<SocialGraph>>(System.IO.File.ReadAllText(path));
_log.Info($"SocialGraph loaded from disk...");

return View(graphs);
throw new NotImplementedException();
// ViewBag.IsEnabled = this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled;
// if (!this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled)
// {
// return View();
// }
//
// var path = SocialGraphJob.GetSocialGraphFile();
// if (!System.IO.File.Exists(path))
// {
// ViewBag.IsEnabled = false;
// return View();
// }
//
// var graphs = JsonConvert.DeserializeObject<List<NpcSocialGraph>>(System.IO.File.ReadAllText(path));
// _log.Info($"SocialGraph loaded from disk...");
//
// return View(graphs);
}

[HttpGet("{id}")]
public IActionResult Detail(Guid id)
{
ViewBag.IsEnabled = this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled;
if (!this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled)
{
return View();
}

var path = SocialGraphJob.GetSocialGraphFile();
if (!System.IO.File.Exists(path))
{
ViewBag.IsEnabled = false;
return View();
}

var graph = JsonConvert.DeserializeObject<List<SocialGraph>>(System.IO.File.ReadAllText(path)).FirstOrDefault(x => x.Id == id);
_log.Info($"SocialGraph loaded from disk...");

return View(graph);
throw new NotImplementedException();
// ViewBag.IsEnabled = this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled;
// if (!this._configuration.AnimatorSettings.Animations.SocialGraph.IsEnabled)
// {
// return View();
// }
//
// var path = SocialGraphJob.GetSocialGraphFile();
// if (!System.IO.File.Exists(path))
// {
// ViewBag.IsEnabled = false;
// return View();
// }
//
// var graph = JsonConvert.DeserializeObject<List<NpcSocialGraph>>(System.IO.File.ReadAllText(path)).FirstOrDefault(x => x.Id == id);
// _log.Info($"SocialGraph loaded from disk...");
//
// return View(graph);
}

[HttpGet("{id}/interactions")]
Expand All @@ -82,52 +84,53 @@ public IActionResult Interactions(string id)
[HttpGet("{id}/file")]
public IActionResult File(Guid id)
{
var path = SocialGraphJob.GetSocialGraphFile();
var graph = JsonConvert.DeserializeObject<List<SocialGraph>>(System.IO.File.ReadAllText(path)).FirstOrDefault(x => x.Id == id);
_log.Info("SocialGraph loaded from disk...");

var interactions = new InteractionMap();
var startTime = DateTime.Now.AddMinutes(-graph.Connections.Count).AddMinutes(-1);
var endTime = DateTime.Now.AddMinutes(1);

var node = new Node
{
id = id.ToString(),
start = startTime,
end = endTime
};
interactions.nodes.Add(node);

foreach (var connection in graph.Connections)
{
if (connection.Interactions.Count < 1)
continue;
node = new Node
{
id = connection.Id.ToString(),
start = startTime.AddMinutes(connection.Interactions.Min(x=>x.Step)),
end = endTime
};
interactions.nodes.Add(node);
}

foreach (var learning in graph.Knowledge)
{
var link = new Link
{
start = startTime.AddMinutes(learning.Step),
source = learning.To.ToString(),
target = learning.From.ToString()
};
link.end = link.start.AddMinutes(1);
interactions.links.Add(link);
}

// var content = System.IO.File.ReadAllText(
// "/Users/dustin/Projects/ghosts-animator/src/ghosts-animator-api/wwwroot/view-social/files/5c0e56b44362ec8e2621299d2ddce5ac68e4e1b11e08ac4547075b0e6374d9083a589eec442479ef7876be75215b8499cf9463743191cfe01e4ca3cb826135e5.json");
var content = JsonConvert.SerializeObject(interactions);
var fileBytes = Encoding.ASCII.GetBytes(content);
return File(fileBytes, "application/json", $"{Guid.NewGuid()}.json");
throw new NotImplementedException();
// var path = SocialGraphJob.GetSocialGraphFile();
// var graph = JsonConvert.DeserializeObject<List<NpcSocialGraph>>(System.IO.File.ReadAllText(path)).FirstOrDefault(x => x.Id == id);
// _log.Info("SocialGraph loaded from disk...");
//
// var interactions = new InteractionMap();
// var startTime = DateTime.Now.AddMinutes(-graph.Connections.Count).AddMinutes(-1);
// var endTime = DateTime.Now.AddMinutes(1);
//
// var node = new Node
// {
// id = id.ToString(),
// start = startTime,
// end = endTime
// };
// interactions.nodes.Add(node);
//
// foreach (var connection in graph.Connections)
// {
// if (connection.Interactions.Count < 1)
// continue;
// node = new Node
// {
// id = connection.Id.ToString(),
// start = startTime.AddMinutes(connection.Interactions.Min(x=>x.Step)),
// end = endTime
// };
// interactions.nodes.Add(node);
// }
//
// foreach (var learning in graph.Knowledge)
// {
// var link = new Link
// {
// start = startTime.AddMinutes(learning.Step),
// source = learning.To.ToString(),
// target = learning.From.ToString()
// };
// link.end = link.start.AddMinutes(1);
// interactions.links.Add(link);
// }
//
// // var content = System.IO.File.ReadAllText(
// // "/Users/dustin/Projects/ghosts-animator/src/ghosts-animator-api/wwwroot/view-social/files/5c0e56b44362ec8e2621299d2ddce5ac68e4e1b11e08ac4547075b0e6374d9083a589eec442479ef7876be75215b8499cf9463743191cfe01e4ca3cb826135e5.json");
// var content = JsonConvert.SerializeObject(interactions);
// var fileBytes = Encoding.ASCII.GetBytes(content);
// return File(fileBytes, "application/json", $"{Guid.NewGuid()}.json");
}


Expand Down
Loading

0 comments on commit 8865ee5

Please sign in to comment.