Skip to content

Commit

Permalink
Export boring name to PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
jswise committed Dec 21, 2020
1 parent 400b71b commit f0fb904
Show file tree
Hide file tree
Showing 21 changed files with 28,759 additions and 0 deletions.
12,372 changes: 12,372 additions & 0 deletions data/samples/600304_20180702.xml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions scratch/ExportPDF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pathlib

from pydiggs.boringlog import BoringLog

def export_log():
samples_dir = pathlib.Path(__file__).parents[1].joinpath('data', 'samples')
sample_file = samples_dir.joinpath('600304_20180702.xml')
log = BoringLog()
log.extract_xml(sample_file)
log.to_pdf(r'C:\Temp\BoringLog.pdf')

if __name__ == '__main__':
export_log()
1 change: 1 addition & 0 deletions scratch/Thoughts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import to gINT
GPJ
enterprise
generate JSON?
diagram
Empty file added src/pydiggs/__init__.py
Empty file.
Binary file added src/pydiggs/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added src/pydiggs/__pycache__/boringlog.cpython-38.pyc
Binary file not shown.
Binary file added src/pydiggs/bin/wkhtmltopdf.exe
Binary file not shown.
47 changes: 47 additions & 0 deletions src/pydiggs/boringlog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Define the BoringLog class."""

import xml.etree.ElementTree as ET
import pathlib

from jinja2 import Environment, PackageLoader, select_autoescape
import pdfkit
import xmlschema

class BoringLog:
def __init__(self):
self.log_data = {}

def extract_xml(self, input_path):
pydiggs_dir = pathlib.Path(__file__).parents[0]
# xsd = str(pydiggs_dir.joinpath('schema', 'Complete.xsd'))
# schema = xmlschema.XMLSchema(xsd)
# xml_data = schema.to_dict('tests/test_cases/examples/collection/collection.xml')
# self.log_data['boring_id'] = 'temp'

namespace = {
'default': 'http://diggsml.org/schemas/2.5.a',
'gml': 'http://www.opengis.net/gml/3.2'
}
tree = ET.parse(input_path)
root = tree.getroot()
first_feature = root.find('default:samplingFeature', namespace)
borehole = first_feature.find('default:Borehole', namespace)
name = borehole.find('gml:name', namespace)
self.log_data['boring_id'] = name.text

def to_pdf(self, output_path):
# output_text = '<p>Pretend this is a boring log.</p>'
# content = {'boring_id': 'B-1'}

pydiggs_dir = pathlib.Path(__file__).parents[0]
# template_file = str(pydiggs_dir.joinpath('templates', 'BoringLog.html'))
env = Environment(
loader=PackageLoader('pydiggs', 'templates'),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.get_template('BoringLog.html')
output_text = template.render(**self.log_data)

wkhtml = str(pydiggs_dir.joinpath('bin', 'wkhtmltopdf.exe'))
config = pdfkit.configuration(wkhtmltopdf=wkhtml)
pdfkit.from_string(output_text, output_path, configuration=config)
238 changes: 238 additions & 0 deletions src/pydiggs/schema/1.3.1.1/typ_baseType.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:witsml="http://www.witsml.org/schemas/131"
targetNamespace="http://www.witsml.org/schemas/131"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
version="1.3.1">

<!-- POSC License Agreement
This file is distributed under the POSC License Agreement at
http://www.posc.org/about/license.shtml.
Use of this file constitutes agreement with the POSC License Agreement.
-->


<!-- -->
<!-- ================= ABSTRACT BASE TYPES ================= -->
<!-- -->
<simpleType name="abstractBoolean">
<annotation>
<documentation>This type disallows an "empty" boolean value.
This type should not be used directly except to derive another type.
All boolean types should be derived from this type rather than using boolen.</documentation>
</annotation>
<restriction base="boolean">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractDateTime">
<annotation>
<documentation>This type disallows an "empty" dateTime value.
This type should not be used directly except to derive another type.
All dateTime types should be derived from this type rather than using dateTime.</documentation>
</annotation>
<restriction base="dateTime">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractDate">
<annotation>
<documentation>This type disallows an "empty" date value.
This type should not be used directly except to derive another type.
All dateTime types should be derived from this type rather than using dateTime.</documentation>
</annotation>
<restriction base="date">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractYear">
<annotation>
<documentation>This type disallows an "empty" gYear value.
This type should not be used directly except to derive another type.
All year types should be derived from this type rather than using gYear.</documentation>
</annotation>
<restriction base="gYear">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractDouble">
<annotation>
<documentation>This type disallows an "empty" double value.
This type should not be used directly except to derive another type.</documentation>
</annotation>
<restriction base="double">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractShort">
<annotation>
<documentation>This type disallows an "empty" short value.
This type should not be used directly except to derive another type.</documentation>
</annotation>
<restriction base="short">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractInt">
<annotation>
<documentation>This type disallows an "empty" int value.
This type should not be used directly except to derive another type.</documentation>
</annotation>
<restriction base="int">
<pattern value=".+"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractString">
<annotation>
<documentation>The intended abstract supertype of all strings.
This abstract type allows the control over whitespace for all strings to be defined at a high level.
This type should not be used directly except to derive another type.</documentation>
</annotation>
<restriction base="string">
<whiteSpace value='collapse'>
<annotation>
<documentation>Replace tab, line feed and carriage return with
a space, collapse contiguous sequences of spaces to a single space
and then remove leading and trailing spaces.</documentation>
</annotation>
</whiteSpace>
<minLength value='1'>
<annotation>
<documentation>The empty string is not allowed.
This constraint conbined with the whiteSpace collapse constraint means
that a blank value is not allowed.</documentation>
</annotation>
</minLength>
</restriction>
</simpleType>
<!-- -->
<complexType name="abstractMeasure" abstract="true">
<annotation>
<documentation>The intended abstract supertype of all quantities that have a value
with a unit of measure. The unit of measure is in the uom attribute of the subtypes.
This type allows all quantities to be profiled to be a 'float' instead of a 'double'.</documentation>
</annotation>
<simpleContent>
<extension base="witsml:abstractDouble"/>
</simpleContent>
</complexType>
<!-- -->
<simpleType name="abstractMaximumLengthString">
<annotation>
<documentation>This defines the maximum acceptable length of a
string that can be stored in a data base.</documentation>
</annotation>
<restriction base="witsml:abstractString">
<maxLength value="4000">
<annotation>
<documentation>This value should be the smallest "maximum
size of a variable length character type" in commonly used DBMSs.
This is the maximum size of a VARCHAR2 in Oracle 8.</documentation>
</annotation>
</maxLength>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractUncollapsedString">
<annotation>
<documentation>The intended abstract supertype of all strings that must maintain whitespace.
The type abstractString should normally be used.
This type should not be used directly except to derive another type.</documentation>
</annotation>
<restriction base="string">
<minLength value='1'>
<annotation>
<documentation>The empty string is not allowed.</documentation>
</annotation>
</minLength>
</restriction>
</simpleType>
<!-- -->
<!-- =========== CONTENT SPECIFIC ABSTRACT TYPES ========== -->
<!-- -->
<simpleType name="abstractPositiveCount">
<annotation>
<documentation>A positive integer (one based count or index) with a maximum value of 32767 (2-bytes).</documentation>
</annotation>
<restriction base="witsml:abstractShort">
<minInclusive value="1">
<annotation>
<documentation>This value cannot be negative or zero.</documentation>
</annotation>
</minInclusive>
</restriction>
</simpleType>
<!-- -->
<!-- ======= CONTENT SPECIFIC ABSTRACT STRING TYPES ======= -->
<!-- -->
<simpleType name="abstractNameString">
<annotation>
<documentation>The intended abstract supertype of all user assigned human
recognizable contextual name types.
There should be no assumption that (interoperable) semantic information will be extracted from the name by a third party.
This type of value is generally not guaranteed to be unique and is not a candidate to be replaced by an enumeration.</documentation>
</annotation>
<restriction base="witsml:abstractString">
<maxLength value="64"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractUidString">
<annotation>
<documentation>The intended abstract supertype of all locally unique identifiers.
The value is not intended to convey any semantic content (e.g., it may be computer generated).
The value is only required to be unique within a context in a document (e.g., defined via key and keyref).
There is no guarantee that the same data in multiple documents will utilize the same uid value
unless enforced by the source of the document (e.g., a document server).
Spaces are not allowed.</documentation>
</annotation>
<restriction base="witsml:abstractString">
<maxLength value="64"/>
<pattern value="[^ ]*"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractCommentString">
<annotation>
<documentation>The intended abstract supertype of all comments or remarks
intended for human consumption.
There should be no assumption that semantics can be extracted from the field by a computer.
Neither should there be an assumption that any two humans will interpret the information
in the same way (i.e., it may not be interoperable).</documentation>
</annotation>
<restriction base="witsml:abstractMaximumLengthString"/>
</simpleType>
<!-- -->
<simpleType name="abstractTypeEnum">
<annotation>
<documentation>The intended abstract supertype of all enumerated "types".
This abstract type allows the maximum length of a type enumeration to be centrally defined.
This type should not be used directly except to derive another type.
It should also be used for uncontrolled strings which are candidates to become enumerations at a future date.</documentation>
</annotation>
<restriction base="witsml:abstractString">
<maxLength value="40"/>
</restriction>
</simpleType>
<!-- -->
<simpleType name="abstractUomEnum">
<annotation>
<documentation>The intended abstract supertype of all "units of measure".
This abstract type allows the maximum length of a UOM enumeration to be centrally defined.
This type is abstract in the sense that it should not be used directly
except to derive another type.</documentation>
</annotation>
<restriction base="witsml:abstractString">
<maxLength value="24"/>
</restriction>
</simpleType>
<!-- -->
</schema>
Loading

0 comments on commit f0fb904

Please sign in to comment.