public static String Translate(string content, lm.Comol.Modules.EduPath.BusinessLogic.Service service, Path path, Int32 idUser, SubActivity subActivity) { String translation = content; if (path != null) { Int32 IdCRole = service.CommunityRoleId(path.Community.Id, idUser); ILookup <StatusStatistic, ActivityStatistic> statdict = null; DateTime?startEpDate = path.StartDate; if (startEpDate.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartedOn), ReplaceChars(startEpDate.Value.ToShortDateString())); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartedOn), ""); } DateTime?endDate = service.GetEpEndDate(path, idUser); if (endDate.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathEndedOn), ReplaceChars(endDate.Value.ToShortDateString())); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathEndedOn), ""); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathName))) translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathName), ReplaceChars(path.Name)); if (!String.IsNullOrEmpty(path.PathCode)) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathCode), ReplaceChars(path.PathCode)); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathCode), ""); } translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathId), ReplaceChars(path.Id.ToString())); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount), path.UnitList.Where(u=> u.Deleted== BaseStatusDeleted.None)); if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathMinCompletion))) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathMinCompletion), path.MinCompletion.ToString() + "%"); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathMinMark))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathMinMark), path.MinCompletion.ToString()); Boolean timeBased = service.CheckEpType(path.EPType, EPType.Time); Int32 totalAct = -1; Int32 notStarted = -1; Int32 started = -1; Int32 completed = -1; Int32 completedAndPassed = -1; // ANCHE SE è AUTO devo verificare ?? //Boolean timeBased = service.CheckEpType(path.EPType, EPType.Time) && service.CheckEpType(path.EPType, EPType.Auto); if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathDuration)) && timeBased) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathDuration), (path.Weight > 0) ? service.ConvertTimeFromLong(path.Weight) : "//"); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount))) { short count = service.GetActiveUnitsCount(path.UnitList, idUser, IdCRole, true, false); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount), count.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.ActivitiesCount))) { totalAct = service.GetActiveActivitiesCount(path.UnitList.SelectMany(x => x.ActivityList).ToList(), idUser, IdCRole, true, false); //foreach (var item in path.UnitList) //{ // count += service.GetActiveActivitiesCount(item.ActivityList , idUser, IdCRole, true, false); //} //totalAct = count; translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.ActivitiesCount), totalAct.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.StartedActivities))) { //if (statdict == null) // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); //started = statdict[StatusStatistic.BrowsedStarted].Count(); started = service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.Started); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.StartedActivities), started.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.CompletedActivities))) { //if (statdict == null) // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); //completed = statdict[StatusStatistic.Started | StatusStatistic.Browsed | StatusStatistic.Completed ].Count(); //completed = statdict[StatusStatistic.Started | StatusStatistic.Browsed | StatusStatistic.CompletedPassed].Count(); completedAndPassed = service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.Completed); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedActivities), completedAndPassed.ToString()); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.NotStartedActivities))) //{ // //if (statdict == null) // // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); // //if (totalAct == -1) // //{ // // totalAct = service.GetActiveActivitiesCount(path.UnitList.SelectMany(x => x.ActivityList).ToList(), idUser, IdCRole, true, false); // //} // //Int32 x = statdict[StatusStatistic.].Count(); // notStarted = totalAct - (started);//service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.None ,true ); // notStarted = (notStarted < 0) ? 0 : notStarted; // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.NotStartedActivities), notStarted.ToString()); //} //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn))) //{ //(!subActivity.UsePathEndDateStatistics || !endDate.HasValue) || (subActivity.UsePathEndDateStatistics && endDate.HasValue && a.CompletedOn <= endDate.Value)); PathStatistic pathStatistic = null; if (!subActivity.UsePathEndDateStatistics || !endDate.HasValue) { pathStatistic = service.ServiceStat.GetPathStat(path.Id, idUser); } else if (subActivity.UsePathEndDateStatistics && endDate.HasValue) { pathStatistic = service.ServiceStat.GetPathStat(path.Id, idUser, endDate.Value); } if (pathStatistic != null) { //TODO:Check epAuto if (service.ServiceStat.CheckStatusStatistic(pathStatistic.Status, StatusStatistic.Completed) || service.ServiceStat.CheckStatusStatistic(pathStatistic.Status, StatusStatistic.CompletedPassed)) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), pathStatistic.CreatedOn.Value.ToShortDateString()); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), ""); } DateTime?compilationStartedOn = pathStatistic.StartDate; if (compilationStartedOn.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartCompilationOn), compilationStartedOn.Value.ToShortDateString()); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartCompilationOn), ""); } } //else //{ // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), "###"); //} //} } return(translation); }
private List <ApplicationStatisticPath> GetPathStatisticsByRange(long[] range) { return(PathStatistic.OrderByDescending(stat => stat.Timestamp).Where(stat => stat.Timestamp > DateTimeOffset.FromUnixTimeMilliseconds(range[0]) && stat.Timestamp < DateTimeOffset.FromUnixTimeMilliseconds(range[1])).ToList()); }