private static RunSolutionResult GetRunResult(ExerciseBlock exercise, string code) { var buildResult = exercise.BuildSolution(code); if (buildResult.HasErrors) { return new RunSolutionResult { IsCompileError = true, ErrorMessage = buildResult.ErrorMessage, ExecutionServiceName = "uLearn" } } ; var result = SandboxRunner.Run(exercise.CreateSubmission(Utils.NewNormalizedGuid(), code)); var runSolutionResult = new RunSolutionResult { IsRightAnswer = result.Verdict == Verdict.Ok && result.GetOutput().NormalizeEoln() == exercise.ExpectedOutput.NormalizeEoln(), ActualOutput = result.GetOutput().NormalizeEoln(), ErrorMessage = result.CompilationOutput, ExecutionServiceName = "this", IsCompileError = result.Verdict == Verdict.CompilationError, ExpectedOutput = exercise.ExpectedOutput.NormalizeEoln(), SubmissionId = 0, }; if (buildResult.HasStyleErrors) { runSolutionResult.IsStyleViolation = true; runSolutionResult.StyleMessage = string.Join("\n", buildResult.StyleErrors.Select(e => e.GetMessageWithPositions())); } return(runSolutionResult); }
private bool IsRightAnswer(RunningResults result, string output, ExerciseBlock exerciseBlock) { if (result.Verdict != Verdict.Ok) { return(false); } /* For sandbox runner */ if (exerciseBlock == null) { return(false); } if (exerciseBlock.ExerciseType == ExerciseType.CheckExitCode) { return(true); } if (exerciseBlock.ExerciseType == ExerciseType.CheckOutput) { var expectedOutput = exerciseBlock?.ExpectedOutput.NormalizeEoln(); return(output.Equals(expectedOutput)); } throw new InvalidOperationException($"Unknown exercise type for checking: {exerciseBlock.ExerciseType}"); }
public ExerciseBuilder(string langId, string prelude) : base(false) { this.prelude = prelude; Exercise = new ExerciseBlock(); Exercise.ValidatorName = "cs"; Exercise.LangId = langId; }
public static string ValidateBlock(ExerciseBlock exBlock) { var valOut = new StringBuilder(); var val = BuildValidator(BuildSlide(exBlock), valOut); val.ValidateExercises(); return(valOut.ToString()); }
public ExerciseSlide( List <SlideBlock> blocks, SlideInfo slideInfo, string title, string id) : base(blocks, slideInfo, title, id) { MaxScore = 5; Exercise = blocks.OfType <ExerciseBlock>().SingleOrDefault(); }
public ExerciseSlide( List <SlideBlock> blocks, SlideInfo slideInfo, string title, Guid id) : base(blocks, slideInfo, title, id) { Exercise = blocks.OfType <ExerciseBlock>().Single(); MaxScore = Exercise.MaxScore; ScoringGroup = Exercise.ScoringGroup ?? ""; }
public void UpdateCell(ExerciseBlock block) { _block = block; ExerciseIsEnabled.TintColor = Colors.InteractableTextColor; ExerciseNameLabel.Text = $"{block.Quantity} {block.CombinedName}"; ExerciseNameLabel.TextColor = Colors.PrimaryColor; ExerciseIsEnabled.SelectedSegment = block.Enabled ? 1 : 0; ExerciseIsEnabled.ValueChanged -= ExerciseSwitch_ValueChanged; ExerciseIsEnabled.ValueChanged += ExerciseSwitch_ValueChanged; BackgroundColor = block.Enabled ? Colors.MainBackgroundColor : Colors.DisabledBackgroundColor; }
public static ExerciseSlide BuildSlide(ExerciseBlock ex) { var unit = new Unit(new UnitSettings { Title = "UnitTitle" }, null); var slideInfo = new SlideInfo(unit, null, 0); return(new ExerciseSlide(new List <SlideBlock> { ex }, slideInfo, "SlideTitle", Guid.Empty, meta: null)); }
public void Start() { answerAn = GetComponentInChildren <AnswerAnimController>(); GameObject ui = GameObject.FindWithTag("UI"); uiSetLevel = ui.GetComponent <SetLevel>(); uiSetSceneColor = ui.GetComponent <SetSceneColor>(); exercB = GetComponent <ExerciseBlock>(); sound = GameObject.FindWithTag("Sound").GetComponent <soundController>(); level = GameObject.FindWithTag("DataController") .GetComponent <DataController>().currentLevel; StartLevel(); }
public override void ViewDidLoad() { base.ViewDidLoad(); var exercisePickerModel = new PickerModel(PickerListHelper.GetExerciseTypeStrings()); _exerciseTypePicker = MirroredPicker.Create(exercisePickerModel, ExerciseType, doneAction: ShowHideCustomName); var repetitionsPickerModel = new PickerModel(Enumerable.Range(1, 100).Select(n => n.ToString()).ToList()); _repetitionTypePicker = MirroredPicker.Create(repetitionsPickerModel, NumberOfRepetitions, doneAction: ShowHideCustomName); if (SelectedExerciseId.HasValue) { _selectedExercise = Data.GetExerciseById(SelectedExerciseId.Value); ExerciseType.Text = _selectedExercise.Type.Humanize(); _exerciseTypePicker.Select((int)_selectedExercise.Type, 0, false); NumberOfRepetitions.Text = _selectedExercise.Quantity.ToString(); _repetitionTypePicker.Select(_selectedExercise.Quantity - 1, 0, false); CustomExerciseName.Text = _selectedExercise.CombinedName; } else { ExerciseType.Text = PickerListHelper.GetExerciseTypeStrings()[0]; _exerciseTypePicker.Select(0, 0, false); NumberOfRepetitions.Text = "10"; _repetitionTypePicker.Select(9, 0, false); CustomExerciseName.Text = string.Empty; } ShowHideCustomName(); AddButtons(); var pickerTextFields = View.Subviews.OfType <PickerUITextField>().ToArray(); Colors.SetTextPrimaryColor(pickerTextFields); CustomExerciseName.BackgroundColor = Colors.MainBackgroundColor; CustomExerciseName.TextColor = Colors.PrimaryColor; }
private void ShowTimeToMovePrompt(ExerciseBlock selectedExercise) { _notificationDialog?.Dismiss(); var timeToMoveMessage = string.Format(Resources.GetString(Resource.String.TimeToMoveMessage), selectedExercise.Quantity, selectedExercise.CombinedName); _notificationDialog = new AlertDialog.Builder(this) .SetTitle(Resource.String.TimeToMoveTitle) .SetMessage(timeToMoveMessage) .SetCancelable(false) .SetPositiveButton(Resource.String.CompletedButtonText, (sender, args) => { Data.MarkExerciseCompleted(selectedExercise.CombinedName, selectedExercise.Quantity); UpdateData(); ResetPromptData(); _checkForIntentData = false; }) .SetNegativeButton(Resource.String.ChangeExerciseButtonText, (sender, args) => { Data.MarkExerciseNotified(selectedExercise.CombinedName, -1 * selectedExercise.Quantity); var nextExercise = Data.GetNextEnabledExercise(); if (nextExercise == null) { Toast.MakeText(this, Resource.String.NoAvailableExercises, ToastLength.Long).Show(); return; } Data.MarkExerciseNotified(nextExercise.CombinedName, nextExercise.Quantity); UpdateData(); ShowTimeToMovePrompt(nextExercise); }) .SetNeutralButton(Resource.String.IgnoreButtonText, (sender, args) => { ResetPromptData(); _checkForIntentData = false; }) .Show(); }
private static RunSolutionResult GetRunResult(ExerciseBlock exercise, string code) { var buildResult = exercise.Solution.BuildSolution(code); if (buildResult.HasErrors) { return new RunSolutionResult { IsCompileError = true, CompilationError = buildResult.ErrorMessage, ExecutionServiceName = "uLearn" } } ; if (buildResult.HasStyleIssues) { return new RunSolutionResult { IsStyleViolation = true, CompilationError = buildResult.StyleMessage, ExecutionServiceName = "uLearn" } } ; var solution = buildResult.SourceCode; var submission = new RunnerSubmition { Code = solution, Id = Utils.NewNormalizedGuid(), Input = "", NeedRun = true }; var result = SandboxRunner.Run(submission); return(new RunSolutionResult { IsRightAnswer = result.Verdict == Verdict.Ok && result.GetOutput().NormalizeEoln() == exercise.ExpectedOutput.NormalizeEoln(), ActualOutput = result.GetOutput().NormalizeEoln(), CompilationError = result.CompilationOutput, ExecutionServiceName = "this", IsCompileError = result.Verdict == Verdict.CompilationError, ExpectedOutput = exercise.ExpectedOutput.NormalizeEoln() }); }
public static System.Web.WebPages.HelperResult Block(ExerciseBlock block, BlockRenderContext context) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { ExerciseBlockData data = context.GetBlockData(block) ?? new ExerciseBlockData(); var action = data.CanSkip ? "$('#ShowSolutionsAlert').modal('show')" : string.Format("window.location='{0}'", data.AcceptedSolutionUrl); var classString = context.IsGuest ? "code-guest" : "code-exercise"; WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<textarea id=\"secretCodeExercise\" class=\"hide\">"); WebViewPage.WriteTo(@__razor_helper_writer, block.ExerciseInitialCode.EnsureEnoughLines(4)); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</textarea>\r\n"); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<textarea class=\"code "); WebViewPage.WriteTo(@__razor_helper_writer, classString); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-lang=\""); WebViewPage.WriteTo(@__razor_helper_writer, block.LangId); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">"); WebViewPage.WriteTo(@__razor_helper_writer, data.LatestAcceptedSolution ?? block.ExerciseInitialCode.EnsureEnoughLines(4)); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</textarea>\r\n"); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<script>\r\n\t\tfunction cleanUserCode() {\r\n\t\t\tvar $secretCodeExercise = $(\'#secretC" + "odeExercise\');\r\n\t\t\t$(\'.code-exercise\')[0].codeMirrorEditor.setValue($secretCodeE" + "xercise.text());\r\n\t\t}\r\n\t</script>\r\n"); if (data.ShowControls) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<div class=\"solution-control btn-group ctrl-group\">\r\n\t\t\t<button type=\"button\" c" + "lass=\"run-solution-button btn btn-primary no-rounds "); WebViewPage.WriteTo(@__razor_helper_writer, data.IsLti ? "run-solution-button-lti" : ""); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-url=\""); WebViewPage.WriteTo(@__razor_helper_writer, data.RunSolutionUrl); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\tRun\r\n\t\t\t</button>\r\n\r\n"); if (!data.DebugView) { var e = ((ExerciseSlide)context.Slide).Exercise.HintsMd; WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t<button id=\"GetHintButton\" type=\"button\" class=\"btn btn-default hints-btn\"\r\n\t" + "\t\t\t\t\tdata-course-id=\""); WebViewPage.WriteTo(@__razor_helper_writer, context.Course.Id); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-slide-index=\""); WebViewPage.WriteTo(@__razor_helper_writer, context.Slide.Index); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-hints-count=\""); WebViewPage.WriteTo(@__razor_helper_writer, e.Count); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\"\r\n\t\t\t\t\t\tdata-url=\""); WebViewPage.WriteTo(@__razor_helper_writer, data.GetHintUrl); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\tGet hint\r\n\t\t\t\t</button>\r\n"); if (!data.IsLti) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t<button type=\"button\" class=\"btn btn-default giveup-btn\" onclick=\""); WebViewPage.WriteTo(@__razor_helper_writer, action); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t\tShow solutions\r\n\t\t\t\t\t</button>\r\n"); } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t<button type=\"button\" class=\"btn btn-default reset-btn no-rounds\" onclick=\"cl" + "eanUserCode()\">\r\n\t\t\t\t\tReset\r\n\t\t\t\t</button>\r\n"); } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t</div>\r\n"); WebViewPage.WriteTo(@__razor_helper_writer, RunErrors()); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<div class=\"panel-group ctrl-group\" id=\"hints-accordion\">\r\n\t\t\t<div id=\"hints-pl" + "ace\"></div>\r\n\t\t</div>\r\n"); if (!data.IsLti) { WebViewPage.WriteTo(@__razor_helper_writer, YouWillLoseScoresDialog(data)); } } if (data.DebugView) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<div>\r\n\t\t\t<h3>Подсказки</h3>\r\n\t\t\t<ol>\r\n"); foreach (var hint in block.HintsMd) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t<li>\r\n\t\t\t\t\t\t"); WebViewPage.WriteTo(@__razor_helper_writer, MvcHtmlString.Create(hint.RenderMd(context.BaseUrl))); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n\t\t\t\t\t</li>\r\n"); } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t</ol>\r\n\t\t\t<h3>Комментарий после решения</h3>\r\n\t\t\t<p>"); WebViewPage.WriteTo(@__razor_helper_writer, block.CommentAfterExerciseIsSolved); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</p>\r\n\t\t</div>\r\n"); } })); }
public static void CreateInstantNotification(ExerciseBlock nextExercise) { CreateNotification(DateTime.Now.AddSeconds(3), nextExercise, false, true); }
private void Initalize(SQLiteConnection conn) { _db = conn; _db.CreateTable <SystemStatus>(); if (!SystemStatus.Any()) { _db.Insert(new SystemStatus { IsFirstRun = true }); } _db.CreateTable <ExerciseSchedule>(); var hasExerciseSchedule = ExerciseSchedules.Any(); if (!hasExerciseSchedule) { var defaultSchedule = ExerciseSchedule.CreateDefaultSchedule(); _db.Insert(defaultSchedule); } _db.CreateTable <ExerciseBlock>(); _db.CreateTable <MostRecentExercise>(); if (!hasExerciseSchedule && !ExerciseBlocks.Any()) { var defaultExercises = ExerciseBlock.CreateDefaultExercises(); _db.InsertAll(defaultExercises); } _db.CreateTable <ExerciseHistory>(); _db.CreateTable <MovementLocation>(); #if DEBUG var now = DateTime.Now.Date; if (!ExerciseHistories.Any(eh => eh.RecordedDate < now)) { _db.InsertAll(new List <ExerciseHistory> { new ExerciseHistory { QuantityNotified = 10, ExerciseName = "test", RecordedDate = DateTime.Now.AddDays(-1), QuantityCompleted = 10 }, new ExerciseHistory { QuantityNotified = 10, ExerciseName = "test", RecordedDate = DateTime.Now.AddDays(-2), QuantityCompleted = 10 }, new ExerciseHistory { QuantityNotified = 10, ExerciseName = "test", RecordedDate = DateTime.Now.AddDays(-3), QuantityCompleted = 10 }, }); } #endif }
public void UpdateExerciseBlock(ExerciseBlock blockToUpdate) { _db.Update(blockToUpdate); }
public void InsertExerciseBlock(ExerciseBlock newExerciseBlock) { _db.Insert(newExerciseBlock); }
private void EnableDisableExercise(object sender, ExerciseBlock exercise) { exercise.Enabled = !exercise.Enabled; Data.UpdateExerciseBlock(exercise); ServiceManager.RestartNotificationServiceIfNeeded(); }
void Cell_SelectedEnabledSwitch(object sender, ExerciseBlock e) { EnabledDisabledSwitchSelected?.Invoke(sender, e); }
public static void CreateExerciseNotification(Data data, Context context, ExerciseBlock nextExercise) { if (nextExercise == null) { return; } var completedIntent = new Intent(context, typeof(CompleteExerciseBroadcastReceiver)); completedIntent.PutExtra(Constants.ExerciseName, nextExercise.CombinedName); completedIntent.PutExtra(Constants.ExerciseQuantity, nextExercise.Quantity); var completedPendingIntent = PendingIntent.GetBroadcast(context, DateTime.Now.Millisecond, completedIntent, PendingIntentFlags.OneShot); var nextIntent = new Intent(context, typeof(ChangeExerciseBroadcastReceiver)); nextIntent.PutExtra(Constants.ExerciseName, nextExercise.CombinedName); nextIntent.PutExtra(Constants.ExerciseQuantity, nextExercise.Quantity); var nextPendingIntent = PendingIntent.GetBroadcast(context, DateTime.Now.Millisecond, nextIntent, PendingIntentFlags.CancelCurrent); var clickIntent = new Intent(context, typeof(ExerciseHistoryActivity)); clickIntent.PutExtra(Constants.ShowMarkedExercisePrompt, true); clickIntent.PutExtra(Constants.ExerciseId, nextExercise.Id); var stackBuilder = TaskStackBuilder.Create(context); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(ExerciseHistoryActivity))); stackBuilder.AddNextIntent(clickIntent); var clickPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.CancelCurrent); data.MarkExerciseNotified(nextExercise.CombinedName, nextExercise.Quantity); var timeToMoveMessage = string.Format(context.Resources.GetString(Resource.String.TimeToMoveMessage), nextExercise.Quantity, nextExercise.CombinedName); var builder = GetBuilder(context, Constants.ExerciseNotificationChannelId) .SetContentTitle(context.Resources.GetString(Resource.String.TimeToMoveTitle)) .SetContentText(timeToMoveMessage) .SetDefaults(NotificationCompat.DefaultVibrate) .SetContentIntent(clickPendingIntent) .SetSound(Android.Net.Uri.Parse(PreferenceManager.GetDefaultSharedPreferences(context).GetString(context.Resources.GetString(Resource.String.NotificationSoundKey), RingtoneManager.GetDefaultUri(RingtoneType.Notification).ToString()))); var changeExerciseButtonText = context.Resources.GetString(Resource.String.ChangeExerciseButtonText); var completedButtonText = context.Resources.GetString(Resource.String.CompletedButtonText); builder .SetPriority((int)NotificationPriority.High) .SetVisibility(NotificationCompat.VisibilityPublic) .SetCategory("reminder") .SetSmallIcon(Resource.Drawable.Mmm_white_icon) .SetColor(Color.Rgb(215, 78, 10)) .AddAction(new NotificationCompat.Action(Resource.Drawable.ic_shuffle_black_24dp, changeExerciseButtonText, nextPendingIntent)) .AddAction(new NotificationCompat.Action(Resource.Drawable.ic_done_black_24dp, completedButtonText, completedPendingIntent)); var notification = builder.Build(); notification.Flags |= NotificationFlags.AutoCancel; var notificationManager = NotificationManagerCompat.From(context); notificationManager?.Notify(Constants.ExerciseNotificationId, notification); }
public static void CreateNotification(DateTime notificationDate, ExerciseBlock nextExercise, bool isRecurring = false, bool isInstant = false) { if (nextExercise == null) { return; } var notificationDictionary = new NSMutableDictionary { { new NSString(Constants.ExerciseName), new NSString(nextExercise.CombinedName) }, { new NSString(Constants.ExerciseQuantity), new NSString(nextExercise.Quantity.ToString()) } }; var defaults = NSUserDefaults.StandardUserDefaults; var soundString = defaults.StringForKey(Constants.UserDefaultsNotificationSoundsKey); var soundEnum = soundString.DehumanizeTo <Constants.NotificationSounds>(); UNUserNotificationCenter.Current.GetNotificationSettings(settings => { var alertsAllowed = (settings.AlertSetting == UNNotificationSetting.Enabled); if (!alertsAllowed) { return; } var content = new UNMutableNotificationContent { Title = "Time to Move", Body = $"It's time to do {nextExercise.Quantity} {nextExercise.CombinedName}", Badge = -1, CategoryIdentifier = Constants.ExerciseNotificationCategoryId, UserInfo = notificationDictionary, Sound = UNNotificationSound.GetSound(Constants.NotificaitonSoundsMap[soundEnum]) }; UNNotificationTrigger trigger; string requestId; if (isInstant) { trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(3, false); requestId = "exerciseNotification_Instant"; } else { var dateComponants = new NSDateComponents { Hour = notificationDate.Hour, Minute = notificationDate.Minute, Second = notificationDate.Second }; trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponants, true); requestId = $"exerciseNotification_{dateComponants.Hour}:{dateComponants.Minute}:{dateComponants.Second}"; } var request = UNNotificationRequest.FromIdentifier(requestId, content, trigger); UNUserNotificationCenter.Current.AddNotificationRequest(request, err => { if (err != null) { // Do something with error... } }); }); }