Commit 6eccb551 authored by Klaus Stein's avatar Klaus Stein
Browse files

Add dfgmap updates

parent baf74185
......@@ -36,6 +36,7 @@ class DfgMap < ApplicationRecord
require 'csv'
def add_dfg_maps(csvfilename, basepath:)
CSV.foreach(csvfilename, headers: true) do |row|
# ok, these are also on the wda, so we may skip them
if row['signature'] =~ /^\s*(StAHH|Carleton University Archive|Ottawa University Archive)/
......@@ -68,6 +69,13 @@ class DfgMap < ApplicationRecord
description: description(row),
place: place
)
if /Ja/.match(row['diss'])
cat = Category.find_by(name: 'GS') ||
Category.create(name: 'GS', description: 'Diss Georg')
map.categories << cat
end
DfgMap.create!(
["placename", "signature", "imgtype", "title", "signer",
"scale", "categories", "structuremapping", "memorial",
......@@ -83,6 +91,14 @@ class DfgMap < ApplicationRecord
end
dfg_map.update!(uploaded: true)
end
# add images to all pending dfg maps
def add_pending_images
DfgMap.where(uploaded: false).each do |dfg_map|
upload_images(dfg_map)
end
end
def description(row)
......@@ -116,6 +132,7 @@ class DfgMap < ApplicationRecord
def search_files(filepath:, basepath:)
return [] unless filepath
searchtree(basepath: basepath)
if dm=filepath.match(/^Ordner:\s+(.*?)\s*$/)
dir = dm[1]
......@@ -148,8 +165,80 @@ class DfgMap < ApplicationRecord
Dir[File.join(basepath,
'{01_Städte_Projekt,03_Schadenskarten}/**/*')]
end
# Second run
def write_combined_csv(base:, select:, dest:, basepath: nil)
CSV.open(base, headers: true) do |csv_base|
csv_base.readline
hds = csv_base.headers.compact + ['diss']
csv_base.rewind
CSV.open(select, headers: true) do |csv_select|
CSV.open(dest, 'wb', write_headers: true,
headers: hds) do |csv|
# we collect data from the basemap
# and provide it through signature or title
sigs = {}
titles = {}
csv_base.each do |row|
t=row['title']
s=row['signature']
t.blank? or titles[t.strip] = row
s.blank? or sigs[s.strip] = row
end
# Now we try to map them
csv_select.each_with_index do |row,i|
next unless row[SI['_x']]
sig = row[SI['Signatur']] and sig.strip!
r1 = sigs[sig]
sigo = row[SI['_sigalt']] and sigo.strip!
r2 = sigs[sigo]
# check for discrepances
r1 && r2 && (r1!=r2) and raise "broken: #{r1['signature']} != #{r2['signature']}"
r = r1 || r2
t = row[SI['Kartenbezeichnung']] and t.strip!
if !r
t.blank? or r = titles[t]
warn "found by title: #{t}" if r
end
if r
fs = row[SI['_filename']] and fs.strip!
fb = r['filepath'] and fb.strip!
if fs.blank? && !fb.blank?
fs = fb
warn "#{i+1} [#{r['signature']}]: using #{fb}"
end
# !fs.blank? && !fb.blank? && (fs!=fb) and warn "caveat: #{fs} != #{fb}"
r['filepath'] = fs
r['title'] = t unless t.blank?
r['diss'] = row[SI['_diss']]
else
warn "no match for #{i+1}: „#{sig}“ „#{sigo}“"
r = {
'placename' => row[SI['Stadt']],
"signature" => row[SI["Signatur"]],
"title" => t,
"filepath" => row[SI['_filename']],
"diss" => row[SI['_diss']],
}
end
csv << r
end
end
end
end
end
end
IMG_SUFFIX = /TIF|tif|jpg|JPG|xmp|bmp|gif/
......@@ -172,4 +261,22 @@ class DfgMap < ApplicationRecord
"Warszawa (Warschau)" => 'Warschau',
"Wroclaw (Breslau)" => 'Breslau'
}
S_Labels = [
'_nr',
'Stadt',
'Signatur',
'_x',
'_filename',
'_300dpi',
'_archivonly',
'_sigalt',
'Kartenbezeichnung',
'_diss',
'_remark',
'_fileold'
]
SI = S_Labels.map.with_index.to_h
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment