Commit f3b4ab34 authored by Adam P. Goucher's avatar Adam P. Goucher

Potentially allow Catagolue to receive syntheses

parent 3fe731d5
Pipeline #56548919 failed with stage
in 3 minutes and 10 seconds
......@@ -151,7 +151,7 @@ public class Census {
if (i % chunkSize == 0) {
log.warning("-- processing objects "+String.valueOf(i - chunkSize + 1)+" to "+String.valueOf(i));
appendMetadatumParallel(datastore, rulestring, datumName, msublist);
updateMetadatumParallel(datastore, rulestring, datumName, msublist, true);
msublist.clear();
safeSleep(1000);
}
......@@ -161,13 +161,13 @@ public class Census {
if (i == 0) { return; }
log.warning("-- processing objects "+String.valueOf(i - (i % chunkSize) + 1)+" to "+String.valueOf(i));
appendMetadatumParallel(datastore, rulestring, datumName, msublist);
updateMetadatumParallel(datastore, rulestring, datumName, msublist, true);
safeSleep(1000);
}
public static void appendMetadatumParallel(DatastoreService datastore, String rulestring, String datumName, Map<String, String> mdatumlist) {
public static void updateMetadatumParallel(DatastoreService datastore, String rulestring, String datumName, Map<String, String> mdatumlist, boolean append) {
Set<Key> setOfKeys = new TreeSet<Key>();
......@@ -176,7 +176,8 @@ public class Census {
setOfKeys.add(datumKey);
}
Map<Key, Entity> metadataEntities = datastore.get(setOfKeys);
Map<Key, Entity> metadataEntities = new HashMap<Key, Entity>();
if (append) { metadataEntities = datastore.get(setOfKeys); }
for (String apgcode : mdatumlist.keySet()) {
Key datumKey = new KeyFactory.Builder("Rule", rulestring).addChild("Object", apgcode).addChild("Metadatum", datumName).getKey();
......@@ -287,7 +288,7 @@ public class Census {
try {
Entity haul = datastore.get(haulKey);
affineAdd(Tabulation.getArbitraryData(haul, "censusData"), -aq);
updateTabulations(rulestring, symmetry, null, null);
updateTabulations(rulestring, symmetry, null, null, false);
Entity census = datastore.get(censusKey);
long newobjects = (long) haul.getProperty("numobjects");
long newsoups = (long) haul.getProperty("numsoups");
......@@ -430,12 +431,12 @@ public class Census {
// Add the census to the existing tabulations:
Census diffcensus = new Census();
Map<String, Boolean> isTooLarge = updateTabulations(rulestring, symmetry, remap, diffcensus);
Map<String, Boolean> isTooLarge = updateTabulations(rulestring, symmetry, remap, diffcensus, false);
// Update census with remapping:
if (diffcensus.table.size() > 0) {
safeSleep(1200);
diffcensus.updateTabulations(rulestring, symmetry, null, null);
diffcensus.updateTabulations(rulestring, symmetry, null, null, false);
}
logLine(writer, "Tabulations updated.");
......@@ -670,7 +671,7 @@ public class Census {
* @param rulestring e.g. b3s23
* @param symmetry e.g. C1
*/
public Map<String, Boolean> updateTabulations(String rulestring, String symmetry, Map<String, String> decomp, Census remapped) {
public Map<String, Boolean> updateTabulations(String rulestring, String symmetry, Map<String, String> decomp, Census remapped, boolean overwrite) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key censusKey = KeyFactory.createKey("Census", rulestring + "/" + symmetry);
......@@ -725,6 +726,15 @@ public class Census {
for (String prefix : prefices) {
Map<String, Long> tcomb = prefixmap.get(prefix);
Map<String, Long> owriters = new HashMap<String, Long>();
if (overwrite) {
for (Map.Entry<String, Long> entry : tcomb.entrySet()) {
owriters.put(entry.getKey(), entry.getValue());
}
}
Key tabulationKey = new KeyFactory.Builder("Census", rulestring + "/" + symmetry).addChild("Tabulation", prefix).getKey();
try {
Entity tabulation = datastore.get(tabulationKey);
......@@ -733,6 +743,10 @@ public class Census {
} catch (EntityNotFoundException e) {
}
for (Map.Entry<String, Long> entry : owriters.entrySet()) {
tcomb.put(entry.getKey(), entry.getValue());
}
Tabulation tnew = new Tabulation(prefix);
boolean nonempty = false;
......
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
......@@ -12,9 +13,57 @@ import javax.servlet.http.HttpServletResponse;
import com.cp4space.payosha256.PayoshaUtils;
import com.cp4space.catagolue.census.CommonNames;
import com.cp4space.catagolue.census.Census;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
public class CommonNamesServlet extends HttpServlet {
public static void updateSynths(String rulestring, BufferedReader reader) {
Census pseudocensus = new Census();
String line = null;
String apgcode = null;
StringBuilder synthData = null;
Map<String, String> syntheses = new HashMap<String, String>();
while ((line = reader.readLine()) != null) {
if ((apgcode == null) && (line.length() >= 8) && (line.substring(0, 8).equals("#CSYNTH "))) {
String[] parts = line.split(" ");
apgcode = parts[1];
pseudocensus.table.put(apgcode, Long.valueOf(parts[3]));
synthData = new StringBuilder();
}
if (apgcode != null) {
synthData.append(line + "\n");
if ((line.length() >= 1) && (line.charAt(0) != '#') && (line.contains("!"))) {
syntheses.put(apgcode, synthData.toString());
apgcode = null;
}
}
}
Census.updateMetadatumParallel(datastore, rulestring, "synthesis", syntheses, false);
String symmetry = "synthesis-costs";
pseudocensus.updateTabulations(rulestring, symmetry, null, null, true);
{
Entity census = new Entity("Census", rulestring + "/" + symmetry);
census.setProperty("uncommittedHauls", 0);
census.setProperty("committedHauls", 0);
census.setProperty("symmetries", symmetry);
census.setProperty("rulestring", rulestring);
census.setProperty("numsoups", -1);
census.setProperty("numobjects", -1);
census.setProperty("lastModified", new Date());
datastore.put(census);
}
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
......@@ -42,6 +91,12 @@ public class CommonNamesServlet extends HttpServlet {
CommonNames.getNamemap(namespace, namemap, false);
} else if (command.equals("OVERWRITE")) {
// do nothing;
} else if (command.equals("SYNTH")) {
updateSynths(namespace, reader);
writer.println("Operation successful.");
return;
} else {
writer.println("Unrecognised operation");
return;
......
Markdown is supported
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