Skip to content

Commit

Permalink
Add drawing coverage script
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyst committed Jan 18, 2021
1 parent 96ab04f commit 4b2f3ac
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 103 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,45 @@ jobs:
./data/_outputs/*.lox
./data/_outputs/*.pdf
./data/_outputs/*.svg
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache Therion
id: cache-therion
uses: actions/cache@v1
with:
path: ${{ env.THERION_PATH }}/bin
key: ${{ runner.os }}-${{ env.THERION_VERSION }}
#========================= INSTALL DEPENDENCIES ========================#
- name: Run apt update
run: sudo apt update
- name: Install Therion compilation dependencies
if: steps.cache-therion.outputs.cache-hit != 'true'
run: sudo apt install -y bwidget lcdf-typetools libtk-img-dev libtk-img libvtk6-dev libvtk6.3 libwxgtk3.0-dev tcl-dev texlive-latex-base # Pre-installed: gcc ghostscript imagemagick libfreetype6-dev libjpeg-dev libpng-dev zlib1g zlib1g-dev
- name: Install Therion runtime dependencies
run: sudo apt install -y libproj-dev texlive-metapost survex
- name: Download and unpack Therion
if: steps.cache-therion.outputs.cache-hit != 'true'
run: |
curl https://github.com/therion/therion/archive/v${THERION_VERSION}.tar.gz -L -O
tar xvzf v${THERION_VERSION}.tar.gz
- name: Build Therion
if: steps.cache-therion.outputs.cache-hit != 'true'
run: |
make -C $THERION_PATH
mkdir ${THERION_PATH}/bin
mv ${THERION_PATH}/therion ${THERION_PATH}/bin/therion
#=========================== GENERATE OUTPUT ===========================#
- name: Generate coverage
run: python3 ./scripts/percentage_drawn.py data/system_migovec.th --json ./data/_outputs/coverage.json --therion-path ${THERION_PATH}/bin/therion
#=============================== UPLOADS ===============================#
- name: Upload Files
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
title: Coverage ${{ github.run_number }}
automatic_release_tag: "coverage"
prerelease: false
files: |
./data/_outputs/coverage.json
105 changes: 2 additions & 103 deletions scripts/create_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,7 @@
import re
import argparse

# Classes


class SourceFile:
name = None
namespace = []

def __init__(self, name, namespace=[]):
self.name = name
self.dirname = dirname(name)
self.namespace = namespace.copy()


class Survey:
source = None
sources = []
survey_dict = {}

def __init__(self, source_path):
self.source = SourceFile(source_path, [])
self.parse(self.source)

def parse(self, source_file):
inputReg = r"(?:\n|^)\s*(?:input|source)\s+\"?([^\s\"]+)?"
surveyReg = r"(?:\n|^)\s*survey\s+(\S+)"
endSurveyReg = r"(?:\n|^)\s*endsurvey"

namespace = source_file.namespace.copy()
data = ""

with open(source_file.name, "r") as file:
data = file.read()

for line in data.splitlines():
match = re.match(surveyReg, line)
if match:
namespace.append(match.group(1))
self.survey_dict[".".join(namespace)] = source_file.name
continue

match = re.match(endSurveyReg, line)
if match:
namespace.pop()
continue

match = re.match(inputReg, line)
if match:
name = abspath(join(source_file.dirname, match.group(1)))
new_file = SourceFile(name, namespace)
self.sources.append(new_file)
self.parse(new_file)

@staticmethod
def convert_from_internal(path):
parts = path.split(".")
return "{}@{}".format(parts[-1], ".".join(list(reversed(parts[0:-1]))))

@staticmethod
def convert_to_internal(path):
parts = path.split("@")
if len(parts) == 1:
return parts[0]
return "{}.{}".format(".".join(list(reversed(parts[1].split(".")))), parts[0])

@staticmethod
def get_survey_name(key):
return key.split(".")[-1]

@staticmethod
def get_survey_namespace(key):
return ".".join(list(reversed(key.split(".")[0:-1])))

def get_survey_key(self, name, namespace):
if name and namespace:
key = "{}.{}".format(".".join(namespace.split(".")[::-1]), name)
if key in self.survey_dict:
return key
else:
similair = []
for key in self.survey_dict.keys():
if name == key:
return key
if name in key:
similair.append(key)
if len(similair) == 1:
return similair[0]
elif len(similair) > 1:
raise Exception(
"Multiple surveys match that name:\n\t{}".format(
"\n\t".join(self.convert_from_internal(key) for key in similair)
)
)
else:
raise Exception("No survey matches that name")
return None

def get_survey_file(self, key):
if key in self.survey_dict:
return self.survey_dict[key]
return None

from helpers.survey import Survey, SourceFile

# Parse arguments

Expand Down Expand Up @@ -176,7 +76,6 @@ def get_survey_file(self, key):

os.system("therion xvi.thconfig")
os.remove("xvi.thconfig")

# Parse the XVI file

stations = {}
Expand Down Expand Up @@ -287,7 +186,7 @@ def get_survey_file(self, key):
if FORMAT == "plt":
plt_command = """{type} 0 {x} {y} S{station} P -9 -9 -9 -9"""

plt_file = """NX D 1 1 1 C{name}.3d\n{points}"""
plt_file = """NX D 1 1 1 C{name}.plt\n{points}"""

plt_lines = []
for line in lines:
Expand Down
107 changes: 107 additions & 0 deletions scripts/helpers/survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import re
from os.path import dirname, abspath, join, splitext


class SourceFile:
name = None
dirname = None
namespace = []
type = None
projection = None

def __init__(self, name, namespace=[]):
self.name = name
self.dirname = dirname(name)
self.namespace = namespace.copy()
self.type = splitext(self.name)[1][1:]
if self.type == "th2":
self.projection = "extended" if "-e.th2" in self.name else "plan"


class Survey:
source = None
sources = []
survey_dict = {}

def __init__(self, source_path):
self.source = SourceFile(source_path, [])
self.parse(self.source)

def parse(self, source_file):
inputReg = r"(?:\n|^)\s*(?:input|source)\s+\"?([^\s\"]+)?"
surveyReg = r"(?:\n|^)\s*survey\s+(\S+)"
endSurveyReg = r"(?:\n|^)\s*endsurvey"

namespace = source_file.namespace.copy()
data = ""

with open(source_file.name, "r") as file:
data = file.read()

for line in data.splitlines():
match = re.match(surveyReg, line)
if match:
namespace.append(match.group(1))
self.survey_dict[".".join(namespace)] = source_file.name
continue

match = re.match(endSurveyReg, line)
if match:
namespace.pop()
continue

match = re.match(inputReg, line)
if match:
name = abspath(join(source_file.dirname, match.group(1)))
new_file = SourceFile(name, namespace)
self.sources.append(new_file)
self.parse(new_file)

@staticmethod
def convert_from_internal(path):
parts = path.split(".")
return "{}@{}".format(parts[-1], ".".join(list(reversed(parts[0:-1]))))

@staticmethod
def convert_to_internal(path):
parts = path.split("@")
if len(parts) == 1:
return parts[0]
return "{}.{}".format(".".join(list(reversed(parts[1].split(".")))), parts[0])

@staticmethod
def get_survey_name(key):
return key.split(".")[-1]

@staticmethod
def get_survey_namespace(key):
return ".".join(list(reversed(key.split(".")[0:-1])))

def get_survey_key(self, name, namespace):
if name and namespace:
key = "{}.{}".format(".".join(namespace.split(".")[::-1]), name)
if key in self.survey_dict:
return key
else:
similair = []
for key in self.survey_dict.keys():
if name == key:
return key
if name in key:
similair.append(key)
if len(similair) == 1:
return similair[0]
elif len(similair) > 1:
raise Exception(
"Multiple surveys match that name:\n\t{}".format(
"\n\t".join(self.convert_from_internal(key) for key in similair)
)
)
else:
raise Exception("No survey matches that name")
return None

def get_survey_file(self, key):
if key in self.survey_dict:
return self.survey_dict[key]
return None
Loading

0 comments on commit 4b2f3ac

Please sign in to comment.