Skip to content

Commit c4cb2fc

Browse files
committed
some fixes
1 parent eac47d7 commit c4cb2fc

3 files changed

Lines changed: 61 additions & 32 deletions

File tree

entrypoint.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@ else
1818
fi
1919

2020
if [ "${COMMAND,,}" = "generate" ]; then
21-
if [ "$#" -lt 2 ]; then
22-
DATABASE="/opt/blocks/db/test/"
23-
else
24-
DATABASE=$2
21+
shift
22+
re='^[0-9]+$'
23+
if ! [[ "$1" =~ $re ]]; then
24+
DATABASE=$1
25+
shift
2526
fi
26-
echo Database $DATABASE
27+
OutputFolder=/out/
28+
CellSize=${1:-1}
29+
CellSpace=${2:-0}
30+
ShowFill=${3:-0}
31+
DATABASE=${DATABASE:-/db}
32+
33+
echo
2734
echo "Starting server..."
2835
$CCONTROL start $ISC_PACKAGE_INSTANCENAME quietly
36+
echo
2937
echo "Generating image..."
30-
$CCONTROL session $ISC_PACKAGE_INSTANCENAME -UBLOCKS "##class(Blocks.BlocksMap).Generate(\"$DATABASE\")"
38+
echo "Database = \"$DATABASE\""
39+
echo "OutputFolder = \"$OutputFolder\""
40+
echo "CellSize = $CellSize"
41+
echo "CellSpace = $CellSpace"
42+
echo "ShowFill = $ShowFill"
43+
rm ${OutputFolder}BlocksMap.{png,bmp}
44+
$CCONTROL session $ISC_PACKAGE_INSTANCENAME -UBLOCKS "##class(Blocks.BlocksMap).Generate(\"$DATABASE\",\"${OutputFolder}\",\"${CellSize}\",\"${CellSpace}\",\"${ShowFill}\")"
45+
echo
3146
echo "Stopping server..."
3247
$CCONTROL stop $ISC_PACKAGE_INSTANCENAME quietly
3348
echo "Finished"

makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
IMAGE=daimor/blocksexplorer
22

3-
PHONY = cache iris
3+
.PHONY: clean cache iris web
4+
5+
build: clean web
6+
7+
web:
8+
cd web && npm ci && npm run build:prod
9+
10+
clean:
11+
rm -rf web/build
412

513
cache:
614
docker build -t $(IMAGE):cache .
@@ -9,5 +17,3 @@ cache:
917
iris:
1018
docker build -f Dockerfile.iris -t $(IMAGE):iris .
1119
docker push $(IMAGE):iris
12-
13-
default: cache iris

server/src/Blocks/BlocksMap.cls

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ Class Blocks.BlocksMap
33

44
Parameter DefaultOutputFolder = "/opt/blocks/out/";
55

6-
ClassMethod Generate(aDirectory = "", pOutputFolder = {..#DefaultOutputFolder}) As %Status
6+
ClassMethod Generate(aDirectory = "", pOutputFolder = {..#DefaultOutputFolder}, cellSize = 1, cellSpace = 0, showFill = 0) As %Status
77
{
88
If '##class(%File).DirectoryExists(pOutputFolder) {
99
Quit $$$ERROR($$$GeneralError, "OutputFolder must exist")
1010
}
1111

1212
Set tSC = ..GenerateMap(aDirectory)
1313
If $$$ISERR(tSC) {
14+
Do $System.OBJ.DisplayError(tSC)
1415
Quit tSC
1516
}
1617

17-
Set tSC = ..DrawMap(.pOutputFolder)
18+
Set tSC = ..DrawMap(.pOutputFolder, cellSize, cellSpace, showFill)
1819
If $$$ISERR(tSC) {
20+
Do $System.OBJ.DisplayError(tSC)
1921
Quit tSC
2022
}
2123

2224
Set tSC = ..ConvertMap(.pOutputFolder)
2325
If $$$ISERR(tSC) {
26+
Do $System.OBJ.DisplayError(tSC)
2427
Quit tSC
2528
}
2629
Quit $$$OK
@@ -36,10 +39,11 @@ ClassMethod ConvertMap(pOutputFolder = {..#DefaultOutputFolder}) As %Status
3639
Quit $$$OK
3740
}
3841

39-
ClassMethod DrawMap(pOutputFolder = {..#DefaultOutputFolder}) As %Status
42+
ClassMethod DrawMap(pOutputFolder = {..#DefaultOutputFolder}, cellSize = 1, cellSpace = 0, showFill = 0) As %Status
4043
{
4144
Set mapGN = $Name(^||BlocksMap)
4245
Do ..initColors()
46+
Set cellSpace = $System.SQL.CEILING(cellSpace / 2) * 2
4347

4448
Set fileName = ##class(%File).NormalizeFilename("BlocksMap.bmp", pOutputFolder)
4549
Do ##class(%File).Delete(fileName)
@@ -50,23 +54,20 @@ ClassMethod DrawMap(pOutputFolder = {..#DefaultOutputFolder}) As %Status
5054

5155
Set $Listbuild(blocks, size) = $Get(@mapGN)
5256

53-
Set cellSize = 20
54-
Set cellSpace = 2
55-
5657
Set width = size * ( cellSize + cellSpace )
5758
Set height = width
5859

59-
Set bfSize = 14 + 40 + (3*width*height)
60+
Set bytesPerPixel = 3
6061
Set bfOffBits = 54
62+
63+
Set bfSize = bfOffBits + (bytesPerPixel*width*height)
6164
Set fileHeader = ""
6265
_ "BM" // WORD bfType
6366
_ ..justify(bfSize, 4) // DWORD bfSize
6467
_ ..justify(0, 2) // WORD bfReserved1
6568
_ ..justify(0, 2) // WORD bfReserved2
6669
_ ..justify(bfOffBits, 4) // DWORD bfOffBits
6770

68-
Set bytesPerPixel = 3
69-
7071
Set biSize = 40
7172
Set biWidth = width
7273
Set biHeight = height
@@ -100,7 +101,7 @@ ClassMethod DrawMap(pOutputFolder = {..#DefaultOutputFolder}) As %Status
100101
For y=biHeight:-1:1 {
101102
Set line = ""
102103
For x=1:1:biWidth {
103-
Set $Listbuild(red, green, blue) = ..getColor(y, x, size, cellSize, cellSpace)
104+
Set $Listbuild(red, green, blue) = ..getColor(y, x, size, cellSize, cellSpace, showFill)
104105
Set color = ""
105106
_ ..justify(red, 1)
106107
_ ..justify(green, 1)
@@ -152,17 +153,22 @@ ClassMethod initColors() As %Status
152153
}
153154
}
154155

155-
ClassMethod getColor(y, x, size, cellSize, cellSpace) As %List
156+
ClassMethod getColor(y, x, size, cellSize, cellSpace, showFill) As %List
156157
{
157158
Set mapGN = $Name(^||BlocksMap)
158-
Set padding = cellSpace \ 2
159+
160+
Set padding = 0
161+
Set spacing = 0
162+
If cellSpace {
163+
Set padding = cellSpace \ 2
164+
165+
Set spacing = (y <= padding) || (x <= padding)
166+
Set spacing = spacing || (x # (cellSize + cellSpace) <= padding)
167+
Set spacing = spacing || (y # (cellSize + cellSpace) <= padding)
168+
}
159169
Set blockX = x - 1 \ (cellSize + cellSpace) + 1
160170
Set blockY = y - 1 \ (cellSize + cellSpace) + 1
161171

162-
Set spacing = (y <= padding) || (x <= padding)
163-
Set spacing = spacing || (x # (cellSize + cellSpace) <= padding)
164-
Set spacing = spacing || (y # (cellSize + cellSpace) <= padding)
165-
166172
If spacing {
167173
Set red = 222
168174
Set green = 222
@@ -171,13 +177,15 @@ ClassMethod getColor(y, x, size, cellSize, cellSpace) As %List
171177
ElseIf $Data(@mapGN@("Map", blockY, blockX), blockInfo) {
172178
Set $Listbuild(globalNum, fill) = blockInfo
173179
Set $Listbuild(red, green, blue) = $Get(@mapGN@("Colors", globalNum))
174-
Set fillSize = $System.SQL.CEILING(fill / 100 * cellSize) + 1
175-
Set:fillSize<1 fillSize = 1
176-
if ( y # (cellSize + cellSpace) > fillSize) {
177-
Set alpha = 0.5
178-
Set red = (1-alpha) * 255 + (alpha * red)
179-
Set green = (1-alpha) * 255 + (alpha * green)
180-
Set blue = (1-alpha) * 255 + (alpha * blue)
180+
if (showFill) {
181+
Set fillSize = $System.SQL.CEILING(fill / 100 * cellSize) + 1
182+
Set:fillSize<1 fillSize = 1
183+
if ( y # (cellSize + cellSpace) > fillSize) {
184+
Set alpha = 0.5
185+
Set red = (1-alpha) * 255 + (alpha * red)
186+
Set green = (1-alpha) * 255 + (alpha * green)
187+
Set blue = (1-alpha) * 255 + (alpha * blue)
188+
}
181189
}
182190
}
183191
Else {

0 commit comments

Comments
 (0)