Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Stats are now displayed. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion LoggingMonkey.Web/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public void Index([FromUri] SearchModel model)
model.FromDate = ConvertQueryValueToDate("FromDate");
model.ToDate = ConvertQueryValueToDate("ToDate");

var beginTime = DateTime.Now;

var messages = MessageRetriever.Get(model);
var vm = new IndexViewModel { Search = model, DisplayOptions = displayOptions, Messages = messages };

var timeSpan = DateTime.Now - beginTime;

var vm = new IndexViewModel { Search = model, DisplayOptions = displayOptions, Messages = messages, TimeElapsedMs = timeSpan.TotalMilliseconds };

UnbufferedRenderer.Render(ControllerContext, ViewData, TempData, Response, vm);
}
Expand Down
27 changes: 15 additions & 12 deletions LoggingMonkey.Web/Helpers/MessageRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace LoggingMonkey.Web.Helpers
{
public static class MessageRetriever
{
private static readonly CachedHashedWebCsvFile Tor = new CachedHashedWebCsvFile (Path.Combine(Path.GetTempPath(), "tor.csv"), @"http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv");
private const string TorIpListAddress = @"http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv";

private static readonly CachedHashedWebCsvFile Tor = new CachedHashedWebCsvFile (Path.Combine(Path.GetTempPath(), "tor.csv"), TorIpListAddress);

public static MessagesModel Get(SearchModel search)
{
Expand All @@ -26,14 +28,14 @@ public static MessagesModel Get(SearchModel search)

var lines = FastLogReader.ReadAllLines(networkName, channelName, search.FromDate.Value, search.ToDate.Value);

Process(output, Filter(lines, search));
Process(output, Filter(lines, search, output));

search.FromDate = prevFromDate;
search.ToDate = prevToDate;

return output;
}
private static IEnumerable<FastLogReader.Line> Filter(IEnumerable<FastLogReader.Line> lines, SearchModel search)
private static IEnumerable<FastLogReader.Line> Filter(IEnumerable<FastLogReader.Line> lines, SearchModel search, MessagesModel output)
{
var regexOptions = RegexOptions.Compiled | (search.IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);

Expand Down Expand Up @@ -73,14 +75,19 @@ public static MessagesModel Get(SearchModel search)
{
// NOTE: The order of these if-statements matters.

output.LinesSearched++;

if (isDirectLineMatch(line))
{
output.LinesMatching++;

// We have a match, but we also have some outstanding context lines to
// print prior to this one, so do that now.
if (search.Context != 0)
{
while (queue.Count != 0)
{
output.LinesDisplaying++;
yield return queue.Dequeue();
}

Expand All @@ -105,11 +112,12 @@ public static MessagesModel Get(SearchModel search)
}

// Fallthrough, print a direct match or one of the current trailing lines.
output.LinesDisplaying++;
yield return line;
}
}

class PreviousMessageState
class MessageState
{
public void InitializeIfBlank(FastLogReader.Line line)
{
Expand All @@ -123,7 +131,7 @@ public bool IsLinePartOfMessage(FastLogReader.Line line)
return (messageExists && nick == line.Nick && type == line.Type && line.When.Subtract(when.Value).Minutes <= 1);
}

public void WriteNewState(FastLogReader.Line line)
public void SetState(FastLogReader.Line line)
{
nick = line.Nick;
type = line.Type;
Expand All @@ -139,14 +147,9 @@ public void WriteNewState(FastLogReader.Line line)

private static void Process(MessagesModel model, IEnumerable<FastLogReader.Line> lines)
{
//
// This process could be refactored into some black LINQ magic, but
// for now, just keep track of previous Nick and Type.
//

Message msg = null;

var previousState = new PreviousMessageState();
var previousState = new MessageState();

foreach (var line in lines)
{
Expand All @@ -162,7 +165,7 @@ private static void Process(MessagesModel model, IEnumerable<FastLogReader.Line>
continue;
}

previousState.WriteNewState(line);
previousState.SetState(line);

msg = new Message { UsesTor = isTor, Type = line.Type, Nick = line.Nick, Timestamp = line.When };

Expand Down
9 changes: 9 additions & 0 deletions LoggingMonkey.Web/Models/IndexViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@ public class IndexViewModel
public SearchModel Search { get; set; }
public DisplayOptionsModel DisplayOptions { get; set; }
public MessagesModel Messages { get; set; }
public double TimeElapsedMs { get; set; }

public string FormattedTimeElapsed
{
get
{
return string.Format("{0:0.00}", TimeElapsedMs/1000.0);
}
}
}
}
6 changes: 5 additions & 1 deletion LoggingMonkey.Web/Models/MessagesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public MessagesModel()

public string ChannelName { get; set; }

public decimal TimeElapsed { get; set; }
public int LinesDisplaying { get; set; }

public int LinesMatching { get; set; }

public int LinesSearched { get; set; }

public List<Message> Messages { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions LoggingMonkey.Web/Views/Unbuffered/PostMessages.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@model LoggingMonkey.Web.Models.IndexViewModel

</div>
<p style="text-align: center;">
@Model.Messages.LinesSearched lines searched. @Model.Messages.LinesMatching lines matched. @Model.Messages.LinesDisplaying lines displayed.
<br />
(@Model.FormattedTimeElapsed seconds)
</p>
</article>