Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-315 Fixing the conversion of current(Year, month, etc.) [WM] #244

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/scratchtocatrobat/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3057,20 +3057,20 @@ def _convert_create_clone_of_block(self):
def _convert_time_and_date_block(self):
[time_or_date] = self.arguments
switcher = {
"second": str(catformula.Sensors.TIME_SECOND),
"minute": str(catformula.Sensors.TIME_MINUTE),
"hour": str(catformula.Sensors.TIME_HOUR),
"day of week": str(catformula.Sensors.DATE_WEEKDAY),
"date": str(catformula.Sensors.DATE_DAY),
"month": str(catformula.Sensors.DATE_MONTH),
"year": str(catformula.Sensors.DATE_YEAR)
"SECOND": str(catformula.Sensors.TIME_SECOND),
"MINUTE": str(catformula.Sensors.TIME_MINUTE),
"HOUR": str(catformula.Sensors.TIME_HOUR),
"DAYOFWEEK": str(catformula.Sensors.DATE_WEEKDAY),
"DATE": str(catformula.Sensors.DATE_DAY),
"MONTH": str(catformula.Sensors.DATE_MONTH),
"YEAR": str(catformula.Sensors.DATE_YEAR)
}
converted_time_or_date = switcher.get(time_or_date, "ERROR")
if converted_time_or_date == "ERROR":
return catbricks.NoteBrick("Can't convert Time-And-Date Block.")
time_formula = catformula.FormulaElement(catformula.FormulaElement.ElementType.SENSOR,
converted_time_or_date, None)
if time_or_date == "day of week":
if time_or_date == "DAYOFWEEK":
time_formula = self._converted_helper_brick_or_formula_element([time_formula, 1], "+")
return time_formula

Expand Down
14 changes: 7 additions & 7 deletions src/scratchtocatrobat/converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1945,28 +1945,28 @@ def test_can_convert_delete_clone_block(self):

# timeAndDate
def test_can_convert_time_and_date_block_second(self):
scratch_block = ["timeAndDate", "second"]
scratch_block = ["timeAndDate", "SECOND"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.TIME_SECOND)

# timeAndDate
def test_can_convert_time_and_date_block_minute(self):
scratch_block = ["timeAndDate", "minute"]
scratch_block = ["timeAndDate", "MINUTE"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.TIME_MINUTE)

# timeAndDate
def test_can_convert_time_and_date_block_hour(self):
scratch_block = ["timeAndDate", "hour"]
scratch_block = ["timeAndDate", "HOUR"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.TIME_HOUR)

# timeAndDate
def test_can_convert_time_and_date_block_weekday(self):
scratch_block = ["timeAndDate", "day of week"]
scratch_block = ["timeAndDate", "DAYOFWEEK"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Operators.PLUS)
Expand All @@ -1975,21 +1975,21 @@ def test_can_convert_time_and_date_block_weekday(self):

# timeAndDate
def test_can_convert_time_and_date_block_date(self):
scratch_block = ["timeAndDate", "date"]
scratch_block = ["timeAndDate", "DATE"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.DATE_DAY)

# timeAndDate
def test_can_convert_time_and_date_block_month(self):
scratch_block = ["timeAndDate", "month"]
scratch_block = ["timeAndDate", "MONTH"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.DATE_MONTH)

# timeAndDate
def test_can_convert_time_and_date_block_year(self):
scratch_block = ["timeAndDate", "year"]
scratch_block = ["timeAndDate", "YEAR"]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catformula.FormulaElement)
assert catr_brick.getValue() == str(catformula.Sensors.DATE_YEAR)
Expand Down
8 changes: 5 additions & 3 deletions src/scratchtocatrobat/scratch/scratch3.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def parse_monitor(monitor):
"motion_xposition": "x position",
"motion_yposition": "y position"
}
MONITOR_CURRENT_MAPPING = {
MONITOR_LABEL_CURRENT_MAPPING = {
"YEAR": "year",
"MONTH": "month",
"DATE": "date",
Expand All @@ -141,7 +141,7 @@ def parse_monitor(monitor):
}
MONITOR_PARAM_MAPPING = {
"data_variable": lambda param: param["VARIABLE"],
"sensing_current": lambda param: MONITOR_CURRENT_MAPPING[param["CURRENTMENU"]]
"sensing_current": lambda param: param["CURRENTMENU"]
}
if not monitor["mode"] in MONITOR_MODE_MAPPING:
log.warn("Monitor with unknown mode will not be created.")
Expand Down Expand Up @@ -175,7 +175,9 @@ def parse_monitor(monitor):
return None
target = monitor.get("spriteName", None)
param = (MONITOR_PARAM_MAPPING[monitor["opcode"]](monitor["params"]) if monitor["opcode"] in MONITOR_PARAM_MAPPING else None)
if monitor["opcode"] in ["data_variable", "sensing_current"]:
if monitor["opcode"] == "sensing_current":
label = MONITOR_LABEL_CURRENT_MAPPING[param]
elif monitor["opcode"] == "data_variable":
label = param
else:
label = MONITOR_LABEL_MAPPING[monitor["opcode"]]
Expand Down
3 changes: 1 addition & 2 deletions src/scratchtocatrobat/scratch/scratch3visitor/sensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def visitTouchingobject(blockcontext):

def visitCurrent(blockcontext):
block = blockcontext.block
time = visitGeneric(blockcontext, "CURRENTMENU")
return ["timeAndDate", time]
return ["timeAndDate", block.fields["CURRENTMENU"][0]]

def visitCurrent_menu(blockcontext):
block = blockcontext.block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,8 @@ def test_visitColoristouchingcolor(self):

def test_visitCurrent(self):
context = create_block_context(opcodes.SENSING_CURRENT)

menublock = createScratch3Block(context, opcodes.SENSING_CURRENT_MENU)
addFieldOfType(menublock, MenuTypes.CURRENT_MENU, AbstractType.YEAR)
addInputOfType(context.block, MenuTypes.CURRENT_MENU, LiteralType.SHADOW_BLOCK, menublock.name)
addFieldOfType(context.block, MenuTypes.CURRENT_MENU, AbstractType.YEAR)
converted_block = visitBlock(context)

assert converted_block[0] == opcodes.opcode_map[opcodes.SENSING_CURRENT]
assert converted_block[1] == AbstractInput.YEAR

Expand Down