Skip to content

Commit

Permalink
fix merge conflicts with debuginput
Browse files Browse the repository at this point in the history
  • Loading branch information
srietkerk committed Jan 5, 2024
2 parents 9ed805e + 289de62 commit 30d3a19
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 23 deletions.
2 changes: 2 additions & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ declare namespace pxt {
timeMachine?: boolean; // Save/restore old versions of a project experiment
blocklySoundVolume?: number; // A number between 0 and 1 that sets the volume for blockly sounds (e.g. connect, disconnect, click)
timeMachineQueryParams?: string[]; // An array of query params to pass to timemachine iframe embed
timeMachineDiffInterval?: number; // An interval in milliseconds at which to take diffs to store in project history. Defaults to 5 minutes
timeMachineSnapshotInterval?: number; // An interval in milliseconds at which to take full project snapshots in project history. Defaults to 15 minutes
}

interface DownloadDialogTheme {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pxt-core",
"version": "9.3.9",
"version": "9.3.10",
"description": "Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors",
"keywords": [
"TypeScript",
Expand Down Expand Up @@ -166,6 +166,6 @@
"test:lang": "gulp testlang",
"update": "gulp update",
"watch-streamer": "cd docs/static/streamer && tsc -t es6 --watch",
"prepare": "cd skillmap && npm install && cd .. && cd authcode && npm install && cd .. && cd multiplayer && npm install && cd .. && cd kiosk && npm install && cd .. && cd teachertool && npm install && cd .."
"prepare": "bash scripts/npm-prepare.sh"
}
}
30 changes: 30 additions & 0 deletions pxtblocks/code-validation/rubric.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace pxt.blocks {
export class Rubric {
criteria: RubricCriteria[];

constructor(criteria: RubricCriteria[]) {
this.criteria = criteria;
}
}

export function parseRubric(rubric: string): Rubric {
let rubricObj;
try {
rubricObj = JSON.parse(rubric);
} catch (e) {
console.error(`Error parsing rubric! ${e}`);
return null;
}

if (!rubricObj.criteria) {
console.error(`No criteria found in rubric`);
return null;
}

const criteria: RubricCriteria[] = rubricObj.criteria.map((c: CriteriaData) => {
return getCriteria(c);
}).filter((r: RubricCriteria) => !!r);

return new Rubric(criteria);
}
}
56 changes: 56 additions & 0 deletions pxtblocks/code-validation/rubricCriteria.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace pxt.blocks {
interface BlockSet {
blocks: string[];
count: number;
}

export interface CriteriaData {
criteriaId: string;
displayText: string;
blockRequirements?: BlockSet[];
count?: number;
}

export function getCriteria(data: CriteriaData): RubricCriteria {
switch (data.criteriaId) {
case "blockCheck":
return new BlockCheckCriteria(data.displayText, data.blockRequirements);
case "comment":
return new CommentCriteria(data.displayText, data.count);
default:
console.error(`Unrecognized criteriaId: ${data.criteriaId}`);
return null;
}
}

export abstract class RubricCriteria {
displayText: string;
abstract criteriaId: string;

constructor(displayText: string) {
this.displayText = displayText;
}
}


class BlockCheckCriteria extends RubricCriteria {
criteriaId: "blockCheck";
blockRequirements: BlockSet[];

constructor(displayText: string, blockRequirements: BlockSet[]) {
super(displayText);
this.blockRequirements = blockRequirements;
}
}

class CommentCriteria extends RubricCriteria {
criteriaId: "comment";
count: number;

constructor(displayText: string, count: number) {
super(displayText);
this.count = count;
}
}

}
30 changes: 23 additions & 7 deletions pxteditor/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace pxt.workspace {
maxTime?: number;
}

// 5 minutes
const DIFF_HISTORY_INTERVAL = 1000 * 60 * 5;
// 5 minutes. This is overridden in pxtarget.json
const DEFAULT_DIFF_HISTORY_INTERVAL = 1000 * 60 * 5;

// 15 minutes
const SNAPSHOT_HISTORY_INTERVAL = 1000 * 60 * 15;
// 15 minutes. This is overridden in pxtarget.json
const DEFAULT_SNAPSHOT_HISTORY_INTERVAL = 1000 * 60 * 15;

const ONE_DAY = 1000 * 60 * 60 * 24;

Expand Down Expand Up @@ -324,7 +324,7 @@ namespace pxt.workspace {
const topTime = history.entries[history.entries.length - 1].timestamp;
const prevTime = history.entries[history.entries.length - 2].timestamp;

if (currentTime - topTime < DIFF_HISTORY_INTERVAL && topTime - prevTime < DIFF_HISTORY_INTERVAL) {
if (currentTime - topTime < diffInterval() && topTime - prevTime < diffInterval()) {
shouldCombine = true;
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ namespace pxt.workspace {
if (history.snapshots.length == 0) {
history.snapshots.push(takeSnapshot(previousText, currentTime - 1));
}
else if (currentTime - history.snapshots[history.snapshots.length - 1].timestamp >= SNAPSHOT_HISTORY_INTERVAL) {
else if (currentTime - history.snapshots[history.snapshots.length - 1].timestamp >= snapshotInterval()) {
history.snapshots.push(takeSnapshot(previousText, currentTime));

const trimmed: pxt.workspace.SnapshotEntry[] = [];
Expand Down Expand Up @@ -441,4 +441,20 @@ namespace pxt.workspace {

return true;
}
}

function diffInterval() {
if (pxt.appTarget?.appTheme?.timeMachineDiffInterval != undefined) {
return pxt.appTarget.appTheme.timeMachineDiffInterval;
}

return DEFAULT_DIFF_HISTORY_INTERVAL;
}

function snapshotInterval() {
if (pxt.appTarget?.appTheme?.timeMachineSnapshotInterval != undefined) {
return pxt.appTarget.appTheme.timeMachineSnapshotInterval;
}

return DEFAULT_SNAPSHOT_HISTORY_INTERVAL;
}
}
7 changes: 7 additions & 0 deletions scripts/npm-prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd skillmap && npm install --no-update-notifier && cd ..
cd authcode && npm install --no-update-notifier && cd ..
cd multiplayer && npm install --no-update-notifier && cd ..
cd kiosk && npm install --no-update-notifier && cd ..
cd teachertool && npm install --no-update-notifier && cd ..
2 changes: 2 additions & 0 deletions teachertool/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<script type="text/javascript" src="/blb/target.js"></script>
<script type="text/javascript" src="/blb/pxtlib.js"></script>
<script type="text/javascript" src="/blb/pxtsim.js"></script>
<script type="text/javascript" src="/blb/pxtblockly.js"></script>
<script type="text/javascript" src="/blb/pxtblocks.js"></script>

<div id="root"></div>

Expand Down
20 changes: 6 additions & 14 deletions teachertool/src/components/DebugInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/// <reference path="../../../built/pxtblocks.d.ts"/>

import { useState } from "react";
import { Button } from "react-common/components/controls/Button";
import { Input } from "react-common/components/controls/Input";
import { Textarea } from "react-common/components/controls/Textarea";
import { getProjectMetaAsync, getProjectTextAsync } from "../services/BackendRequests";
import { loadProjectAsync } from "../transforms/loadProjectAsync";
import { runEvaluateAsync } from "../transforms/runEvaluateAsync";

interface IProps {}

Expand All @@ -12,20 +14,10 @@ const DebugInput: React.FC<IProps> = ({}) => {
const [rubric, setRubric] = useState("");
const [bools, setBools] = useState(true);

const runEvaluate = async () => {
console.log(`Evaluate ${shareLink} with ${rubric}!`);
const scriptId = pxt.Cloud.parseScriptId(shareLink);
const evaluate = async () => {
setBools(!bools);
if (!scriptId) {
console.log("Invalid share link!");
return;
}
const projText = await getProjectTextAsync(scriptId);
await runEvaluateAsync(shareLink, rubric);
loadProjectAsync("hi", bools);
if (projText) console.log(projText["main.blocks"] || "Failed to get blocks xml!");

const projMeta = await getProjectMetaAsync(scriptId);
if (projMeta) console.log(projMeta);
}

return (
Expand All @@ -47,7 +39,7 @@ const DebugInput: React.FC<IProps> = ({}) => {
rows={20}
onChange={setRubric} />
</div>
<Button id="evaluateSingleProjectButton" className="primary" onClick={runEvaluate} title={"Evaluate"} label={lf("Evaluate")} />
<Button id="evaluateSingleProjectButton" className="primary" onClick={evaluate} title={"Evaluate"} label={lf("Evaluate")} />
</div>
)

Expand Down
17 changes: 17 additions & 0 deletions teachertool/src/transforms/runEvaluateAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getProjectMetaAsync, getProjectTextAsync } from "../services/BackendRequests";

export async function runEvaluateAsync(shareLink: string, rubric: string) {
console.log(`Evaluate ${shareLink} with ${rubric}!`);
const scriptId = pxt.Cloud.parseScriptId(shareLink);
if (!scriptId) {
console.log("Invalid share link!");
return;
}
const projText = await getProjectTextAsync(scriptId);
if (projText) console.log(projText["main.blocks"] || "Failed to get blocks xml!");

const projMeta = await getProjectMetaAsync(scriptId);
if (projMeta) console.log(projMeta);

console.log(pxt.blocks.parseRubric(rubric));
}

0 comments on commit 30d3a19

Please sign in to comment.