Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/13 17:03:43 (12 years ago)
Author:
pfleck
Message:

#2063:
UserId in ClientInfo fact table is nullable. UserId is removed from primary key therefore.
StatisticsGenerator insert new ClientInfo into fact table.

Location:
branches/HiveStatistics/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml

    r9538 r9541  
    277277      <Column Name="ClientId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    278278      <Column Name="Time" Type="System.DateTime" DbType="DateTime NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    279       <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
     279      <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier NULL" CanBeNull="true" />
    280280      <Column Name="NumUsedCores" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    281281      <Column Name="NumTotalCores" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout

    r9538 r9541  
    121121      </nestedChildShapes>
    122122    </classShape>
    123     <associationConnector edgePoints="[(11.25 : 1.87677124023437); (10.9375 : 1.87677124023437); (10.9375 : 0.6875); (2.75 : 0.6875); (2.75 : 1)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     123    <associationConnector edgePoints="[(11.25 : 1.44547136382195); (11.0260416666667 : 1.44547136382195); (11.0260416666667 : 0.5625); (2.75 : 0.5625); (2.75 : 1)]" manuallyRouted="true" fixedFrom="Caller" fixedTo="Algorithm">
    124124      <AssociationMoniker Name="/HiveDataContext/Resource/Resource_StateLog" />
    125125      <nodes>
     
    179179      </nodes>
    180180    </associationConnector>
    181     <associationConnector edgePoints="[(7.96163946463664 : 4.30930826822917); (7.96163946463664 : 5.09699625651042); (8.875 : 5.09699625651042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     181    <associationConnector edgePoints="[(8.0192961430407 : 3.90397379557292); (8.0192961430407 : 5.04807657877604); (8.875 : 5.04807657877604)]" fixedFrom="Caller" fixedTo="Algorithm">
    182182      <AssociationMoniker Name="/HiveDataContext/Task/Task_AssignedResource" />
    183183      <nodes>
     
    186186      </nodes>
    187187    </associationConnector>
    188     <associationConnector edgePoints="[(7.16831973231832 : 4.30930826822917); (7.16831973231832 : 5.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     188    <associationConnector edgePoints="[(7.20145120722822 : 3.90397379557292); (7.20145120722822 : 5.875)]" fixedFrom="Caller" fixedTo="Algorithm">
    189189      <AssociationMoniker Name="/HiveDataContext/Task/Task_RequiredPlugin" />
    190190      <nodes>
     
    193193      </nodes>
    194194    </associationConnector>
    195     <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.875); (7.80461538461539 : 0.875); (7.80461538461539 : 1)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     195    <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.770833333333333); (7.80461538461539 : 0.770833333333333); (7.80461538461539 : 1)]" manuallyRouted="true" fixedFrom="Algorithm" fixedTo="Algorithm">
    196196      <AssociationMoniker Name="/HiveDataContext/Task/Task_Task" />
    197197      <nodes>
     
    297297      </nodes>
    298298    </associationConnector>
    299     <associationConnector edgePoints="[(5.15625 : 10.0891951497396); (5.15625 : 14.3889184570313); (6.875 : 14.3889184570313)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     299    <associationConnector edgePoints="[(5.15625 : 10.0891951497396); (5.15625 : 14.3889184570313); (6.875 : 14.3889184570313)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    300300      <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactTask" />
    301301      <nodes>
     
    304304      </nodes>
    305305    </associationConnector>
    306     <associationConnector edgePoints="[(5.4218775 : 10.0891951497396); (5.4218775 : 13.3576659570313); (6.71675495975 : 13.3576659570313); (6.71675495975 : 13.359301744963); (6.875 : 13.359301744963)]" manuallyRouted="true" fixedFrom="Algorithm" fixedTo="Caller">
     306    <associationConnector edgePoints="[(5.4218775 : 10.0891951497396); (5.4218775 : 13.3576659570313); (6.71675495975 : 13.3576659570313); (6.71675495975 : 13.359301744963); (6.875 : 13.359301744963)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
    307307      <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactTask1" />
    308308      <nodes>
     
    318318      </nodes>
    319319    </associationConnector>
    320     <associationConnector edgePoints="[(4.125 : 10.0891951497396); (4.125 : 11)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     320    <associationConnector edgePoints="[(4.125 : 10.0891951497396); (4.125 : 11)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    321321      <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactClientInfo" />
    322322      <nodes>
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs

    r9538 r9541  
    59295929    private System.DateTime _Time;
    59305930   
    5931     private System.Guid _UserId;
     5931    private System.Nullable<System.Guid> _UserId;
    59325932   
    59335933    private int _NumUsedCores;
     
    59695969    partial void OnTimeChanging(System.DateTime value);
    59705970    partial void OnTimeChanged();
    5971     partial void OnUserIdChanging(System.Guid value);
     5971    partial void OnUserIdChanging(System.Nullable<System.Guid> value);
    59725972    partial void OnUserIdChanged();
    59735973    partial void OnNumUsedCoresChanging(int value);
     
    60536053    }
    60546054   
    6055     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
    6056     public System.Guid UserId
     6055    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier NULL")]
     6056    public System.Nullable<System.Guid> UserId
    60576057    {
    60586058      get
     
    64126412          else
    64136413          {
    6414             this._UserId = default(System.Guid);
     6414            this._UserId = default(Nullable<System.Guid>);
    64156415          }
    64166416          this.SendPropertyChanged("DimUser");
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql

    r9538 r9541  
    233233    [ClientId]              UNIQUEIDENTIFIER NOT NULL,
    234234    [Time]                  DATETIME         NOT NULL,
    235     [UserId]                UNIQUEIDENTIFIER NOT NULL,
     235    [UserId]                UNIQUEIDENTIFIER NULL,
    236236    [NumUsedCores]          INT              NOT NULL,
    237237    [NumTotalCores]         INT              NOT NULL,
     
    246246    [TotalTimeOffline]      FLOAT (53)       NOT NULL,
    247247    [TotalTimeUnavailable]  FLOAT (53)       NOT NULL,
    248     CONSTRAINT [PK_FactClientInfo] PRIMARY KEY CLUSTERED ([ClientId] ASC, [Time] ASC, [UserId] ASC),
     248    CONSTRAINT [PK_FactClientInfo] PRIMARY KEY CLUSTERED ([ClientId] ASC, [Time] ASC),
    249249    CONSTRAINT [FK_FactClientInfo_DimTime] FOREIGN KEY ([Time]) REFERENCES [statistics].[DimTime] ([Time]),
    250250    CONSTRAINT [FK_FactClientInfo_DimClient] FOREIGN KEY ([ClientId]) REFERENCES [statistics].[DimClient] ([Id]),
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs

    r9538 r9541  
    66namespace HeuristicLab.Services.Hive {
    77  public class HiveStatisticsGenerator : IStatisticsGenerator {
    8     private static readonly TimeSpan SmallesTimeSpan = new TimeSpan(0, 5, 0);
     8    private static readonly TimeSpan SmallestTimeSpan = new TimeSpan(0, 5, 0);
    99
    1010    public void GenerateStatistics() {
    1111      using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString))
    1212      using (var transaction = new TransactionScope()) {
    13 
    1413        var newTime = UpdateDimensionTables(db);
     14        db.SubmitChanges();
     15
    1516        if (newTime != null) {
    16           UpdateDataTables(newTime, db);
     17          UpdateFactTables(newTime, db);
     18          db.SubmitChanges();
    1719        }
    1820
    19         db.SubmitChanges();
    2021        transaction.Complete();
    2122      }
     
    4142      var now = DateTime.Now;
    4243      DimTime newTime = null;
    43       if (lastUpdate == default(DateTime) || lastUpdate + SmallesTimeSpan < now) {
     44      if (lastUpdate == default(DateTime) || lastUpdate + SmallestTimeSpan < now) {
    4445        newTime = new DimTime {
    45           Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - now.Minute % SmallesTimeSpan.Minutes, 0),
     46          Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - now.Minute % SmallestTimeSpan.Minutes, 0),
    4647          Hour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0),
    4748          Day = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0),
     
    131132    }
    132133
    133     private void UpdateDataTables(DimTime newTime, HiveDataContext db) {
    134 
     134    private void UpdateFactTables(DimTime newTime, HiveDataContext db) {
     135      UpdateClientInfoFacts(newTime, db);
     136      //UpdateTaskFacts(newTime, db);
     137    }
     138
     139    private void UpdateClientInfoFacts(DimTime newTime, HiveDataContext db) {
     140      var lastFacts =
     141        from cf in db.FactClientInfos
     142        group cf by cf.ClientId
     143          into grpFacts
     144          select grpFacts.OrderByDescending(x => x.Time).First();
     145
     146      var slaves =
     147        from s in db.Resources.OfType<Slave>()
     148        join c in db.DimClients on s.ResourceId equals c.ResourceId
     149        join lcf in lastFacts on c.Id equals lcf.ClientId into joinCf
     150        from cf in joinCf.DefaultIfEmpty()
     151        select new {
     152          Slave = s,
     153          Client = c,
     154          LastFact = cf
     155        };
     156
     157      var clientFacts =
     158        from s in slaves.ToList()
     159        select new FactClientInfo {
     160          DimClient = s.Client,
     161          DimTime = newTime,
     162          UserId = s.Slave.OwnerUserId,
     163          NumUsedCores =
     164            s.Slave.Cores != null && s.Slave.FreeCores != null
     165              ? s.Slave.Cores.Value - s.Slave.FreeCores.Value
     166              : 0,
     167          NumTotalCores = s.Slave.Cores ?? 0,
     168          UsedMemory =
     169            s.Slave.Memory != null && s.Slave.FreeMemory != null
     170              ? s.Slave.Memory.Value - s.Slave.FreeMemory.Value
     171              : 0,
     172          TotalMemory = s.Slave.Memory ?? 0,
     173          CpuUtilization = s.Slave.CpuUtilization,
     174          TrafficIn = 0,
     175          TrafficOut = 0,
     176          TotalTimeIdle = CalcNewTotalTime(s.LastFact, newTime.Time,
     177                                           x => x.TotalTimeIdle,
     178                                           () => s.Slave.SlaveState == SlaveState.Idle && s.Slave.IsAllowedToCalculate),
     179          TotalTimeCalculating = CalcNewTotalTime(s.LastFact, newTime.Time,
     180                                                  x => x.TotalTimeCalculating,
     181                                                  () => s.Slave.SlaveState == SlaveState.Calculating),
     182          TotalTimeTransferring = 0.0,
     183          TotalTimeUnavailable = CalcNewTotalTime(s.LastFact, newTime.Time,
     184                                                  x => x.TotalTimeUnavailable,
     185                                                  () => s.Slave.SlaveState == SlaveState.Idle && !s.Slave.IsAllowedToCalculate),
     186          TotalTimeOffline = CalcNewTotalTime(s.LastFact, newTime.Time,
     187                                              x => x.TotalTimeOffline,
     188                                              () => s.Slave.SlaveState == SlaveState.Offline)
     189        };
     190
     191      db.FactClientInfos.InsertAllOnSubmit(clientFacts);
     192    }
     193
     194    private double CalcNewTotalTime(FactClientInfo lastFact, DateTime newTime, Func<FactClientInfo, double> selector, Func<bool> condition) {
     195      if (lastFact == null) {
     196        return 0.0;
     197      }
     198      return condition()
     199               ? selector(lastFact) + (newTime - lastFact.Time).TotalMinutes
     200               : selector(lastFact);
    135201    }
    136202  }
Note: See TracChangeset for help on using the changeset viewer.