Revert "清理"
猿人易 authored at 2024-06-17 16:53:31
2.54 KiB
Stardust
@model IList<SampleData>
@using Stardust.Data.Monitors
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@using System.Web;
@{
    var page = ViewBag.Page as Pager;
    var list = Model;

    // 连续应用,构建为一行,取最大最小时间
    var rs = new List<SampleData>();

    SampleData current = null;
    foreach (var item in list)
    {
        if (current == null || current.AppId != item.AppId)
        {
            current = new SampleData { ItemId = item.ItemId, StartTime = item.StartTime, EndTime = item.EndTime };
            rs.Add(current);
        }
        else
        {
            if (item.StartTime < current.StartTime) current.StartTime = item.StartTime;
            if (item.EndTime > current.EndTime) current.EndTime = item.EndTime;
        }
    }
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            <th class="text-center">应用</th>
            <th style="width:80%">时间轴</th>
        </tr>
    </thead>
    <tbody>
        @{
            var min = Model.Min(e => e.StartTime);
            var max = Model.Max(e => e.EndTime);
            var length = max - min;
        }
        @foreach (var entity in rs)
        {
            var msg = entity.Error ?? entity.Tag;

            var ms = entity.EndTime - entity.StartTime;
            var left = (Double)(entity.StartTime - min) / length;
            if (left < 0) left = 0;
            var w = (Double)ms / length;
            if (w > 0.01) w -= 0.01;
            var color = "lightgreen";
            var url1 = $"/Monitors/appDayStat?monitorId={entity.AppId}";
            <tr>
                <td class="text-center"><a href="@url1" title="应用最近的监控图表">@entity.AppName</a></td>
                <td title="@msg">
                    @if (left < 0.96)
                    {
                        <div style="float:left;width:@left.ToString("p")">&nbsp;</div>
                        <div style="background-color: @color;float:left;width:@w.ToString("p")">@ms.ToString("n0")ms</div>
                    }
                    else
                    {
                        <div style="float:left;width:@((left-0.04).ToString("p"))">&nbsp;</div>
                        <div style="float:left;width:4%">@ms.ToString("n0")ms</div>
                        <div style="background-color: @color;float:left;width:@w.ToString("p")">&nbsp;</div>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>