Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar API cleanup #4201

Merged
merged 155 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
ec5f461
First refactoring.
chipkent Jun 27, 2023
756dbac
First refactoring.
chipkent Jun 27, 2023
eb583ec
Add local date chronology methods.
chipkent Jun 27, 2023
0bd59cf
Calendar refactoring and cleanup.
chipkent Jun 27, 2023
3afab43
Calendar refactoring and cleanup.
chipkent Jun 27, 2023
527cb3a
Calendar refactoring and cleanup.
chipkent Jun 27, 2023
475d8f8
Calendar refactoring and cleanup.
chipkent Jun 28, 2023
fabbe4a
BusinessCalendar refactoring and cleanup.
chipkent Jul 1, 2023
ca2040d
BusinessCalendar refactoring and cleanup.
chipkent Jul 1, 2023
b334e22
BusinessPeriod BusinessSchedule refactoring and cleanup.
chipkent Jul 2, 2023
91cc545
BusinessCalendar refactoring and cleanup:
chipkent Jul 2, 2023
185a014
BusinessCalendar refactoring and cleanup:
chipkent Jul 4, 2023
82d04be
BusinessCalendar refactoring and cleanup:
chipkent Jul 4, 2023
83e3b9d
BusinessCalendar refactoring and cleanup:
chipkent Jul 4, 2023
9bade1c
BusinessCalendar refactoring and cleanup:
chipkent Jul 5, 2023
611a2ec
BusinessCalendar refactoring and cleanup:
chipkent Jul 5, 2023
720df95
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
14fb234
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
591b8fe
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
e0f5d2c
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
ce255f9
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
0175576
BusinessCalendar refactoring and cleanup:
chipkent Jul 7, 2023
decb87b
BusinessCalendar refactoring and cleanup:
chipkent Jul 10, 2023
6fa4077
BusinessCalendar refactoring and cleanup:
chipkent Jul 11, 2023
3af05d3
Calendar refactoring and cleanup:
chipkent Jul 11, 2023
f92b1f2
DateTimeUtils added todayDate plus formatting LocalDate.
chipkent Jul 11, 2023
d1147bd
Todo cleanup:
chipkent Jul 11, 2023
cb5b667
Todo and docs cleanup:
chipkent Jul 11, 2023
2d15d11
Todo and docs and formatting cleanup:
chipkent Jul 11, 2023
860f615
Todo and docs and formatting cleanup:
chipkent Jul 11, 2023
cbf6461
Todo and docs and formatting cleanup:
chipkent Jul 11, 2023
124de3e
Todo and docs and formatting cleanup:
chipkent Jul 11, 2023
55e1dec
Unit test:
chipkent Jul 11, 2023
6b9d0b2
Unit test:
chipkent Jul 11, 2023
1c46647
Unit test:
chipkent Jul 11, 2023
14ee357
Unit test:
chipkent Jul 12, 2023
4cc5066
Unit test:
chipkent Jul 12, 2023
c50eb37
Unit test:
chipkent Jul 12, 2023
d875692
Unit test:
chipkent Jul 12, 2023
6aefb0d
Unit test:
chipkent Jul 12, 2023
d92f6c5
Unit test:
chipkent Jul 17, 2023
03eda36
Unit test:
chipkent Jul 17, 2023
f1bc1be
Unit test:
chipkent Jul 17, 2023
54b0d65
Unit test:
chipkent Jul 17, 2023
c4b67fd
Committing to rebase
chipkent Jul 17, 2023
c3536ef
Merge remote-tracking branch 'origin/main' into cal_upgrades
chipkent Jul 17, 2023
fdaef8d
Committing to rebase
chipkent Jul 18, 2023
e4eedf6
Rebase
chipkent Oct 30, 2023
a4d9605
Updated doc string.
chipkent Oct 30, 2023
f9c190c
Updated doc string. Added a weekendDays getter.
chipkent Oct 31, 2023
c61aa38
Updated doc string. Added a weekendDays getter.
chipkent Oct 31, 2023
ae26972
Renamed todayDate to todayLocalDate. (partial commit)
chipkent Oct 31, 2023
54c44de
Add LocalDate arithmetic.
chipkent Oct 31, 2023
6cd75fb
Updating calendar configs.
chipkent Oct 31, 2023
6fd7e2f
Updating calendar configs.
chipkent Oct 31, 2023
849fe1c
Refactoring code gen
chipkent Nov 1, 2023
582d4bd
Refactoring code gen
chipkent Nov 1, 2023
27dd6a8
Make axis transforms compile
chipkent Nov 1, 2023
986ad6b
Refactoring code gen. Not fully working.
chipkent Nov 1, 2023
7631d13
Updated GroovyStaticImports
chipkent Nov 3, 2023
7d915b6
Refactoring code gen. Not fully working.
chipkent Nov 3, 2023
15fc1f9
Figure interface
chipkent Nov 3, 2023
dc5324a
Figure interface
chipkent Nov 3, 2023
6e8740f
FigureImpl
chipkent Nov 3, 2023
37610de
Refactoring code gen.
chipkent Nov 3, 2023
e762d1b
Refactoring code gen.
chipkent Nov 3, 2023
b941cad
Refactoring code gen.
chipkent Nov 3, 2023
9bb1c7b
Refactoring code gen.
chipkent Nov 3, 2023
74e4e2c
Refactoring code gen.
chipkent Nov 3, 2023
37fb493
Refactoring code gen.
chipkent Nov 3, 2023
64f1799
StaticCalendarMethods
chipkent Nov 3, 2023
f4d238d
Refactoring code gen.
chipkent Nov 3, 2023
c443bce
Renamed currentDate to calendarDate
chipkent Nov 3, 2023
51beefd
Add calendar methods to groovy.
chipkent Nov 3, 2023
18464d2
Add calendar methods to ColumnExpressionValidator.
chipkent Nov 3, 2023
bee8f33
Working on tests.
chipkent Nov 3, 2023
eb03694
Working on tests.
chipkent Nov 3, 2023
31d3175
StaticCalendarMethods
chipkent Nov 3, 2023
c5c199b
Spotless
chipkent Nov 3, 2023
162800b
Update calendar files
chipkent Nov 6, 2023
2c4567f
Addressing tests.
chipkent Nov 6, 2023
7514c06
Automatically test all static calendar methods in query strings and a…
chipkent Nov 6, 2023
1363c94
Improve test coverage.
chipkent Nov 6, 2023
b480afb
Improve test coverage.
chipkent Nov 6, 2023
edc39e0
spotless
chipkent Nov 6, 2023
6a2a20d
Python API and unit tests.
chipkent Nov 7, 2023
41901fc
Spotless
chipkent Nov 7, 2023
13ebbc5
Create a numpy business calendar.
chipkent Nov 7, 2023
8bfe4b3
Create a BusinessCalendar dtype.
chipkent Nov 7, 2023
8dfd527
Merge remote-tracking branch 'origin/main' into cal_upgrades
chipkent Nov 7, 2023
82e30d5
Fixed figure.py
chipkent Nov 7, 2023
8e51976
Fixed unit tests
chipkent Nov 8, 2023
b9cd139
Fixed unit tests
chipkent Nov 8, 2023
f2d4167
Fixed unit tests
chipkent Nov 8, 2023
e30d23d
Addressing code review.
chipkent Nov 20, 2023
70dd8cb
Addressing code review.
chipkent Nov 20, 2023
26bc1c4
Addressing code review.
chipkent Nov 20, 2023
796651c
Addressing code review.
chipkent Nov 20, 2023
bfa59f8
Addressing code review.
chipkent Nov 20, 2023
f048fae
Elijah's updated calendars, only from authoritative sources.
chipkent Nov 20, 2023
82aaf0f
Spotless
chipkent Nov 20, 2023
4eff978
Reduce logging level.
chipkent Nov 21, 2023
a69a047
Function rename
chipkent Nov 21, 2023
76f83cd
Function/Class rename
chipkent Nov 21, 2023
c5bcf1d
Addressing review comments.
chipkent Nov 21, 2023
a666d3b
Fixed broken unit test.
chipkent Nov 21, 2023
90b6544
Added a new calendar integration test and fix test failures.
chipkent Nov 21, 2023
252b305
Test numpy calendars with a bus calendar with no business time.
chipkent Nov 21, 2023
438bf02
Update engine/time/src/main/java/io/deephaven/time/calendar/BusinessC…
chipkent Nov 29, 2023
e79c062
Update engine/time/src/main/java/io/deephaven/time/calendar/BusinessD…
chipkent Nov 29, 2023
fdba4f9
Update engine/time/src/main/java/io/deephaven/time/calendar/BusinessC…
chipkent Nov 29, 2023
35b43ca
Update py/server/deephaven/calendar.py
chipkent Nov 29, 2023
5dcdec8
Update py/server/deephaven/calendar.py
chipkent Nov 29, 2023
39be342
Address review comments.
chipkent Nov 29, 2023
f77e453
Address review comments.
chipkent Nov 29, 2023
993f9f6
Address review comments.
chipkent Nov 29, 2023
dc63eca
Address review comments.
chipkent Nov 29, 2023
4fa5585
Address review comments.
chipkent Nov 29, 2023
b7c0615
Address review comments.
chipkent Nov 29, 2023
97ecf95
Address review comments.
chipkent Nov 29, 2023
6350f86
Address review comments.
chipkent Nov 29, 2023
34da67a
Address review comments.
chipkent Nov 29, 2023
c59271c
Address review comments. Name changes.
chipkent Dec 5, 2023
4475018
Address review comments. Name changes.
chipkent Dec 5, 2023
6c87ed0
Address review comments. Regenerate and format.
chipkent Dec 5, 2023
ef4d833
Address review comments. Regenerate and format.
chipkent Dec 5, 2023
ba73e33
Address review comments. Improve multi-threaded performance.
chipkent Dec 5, 2023
f972cb5
Address review comments. Corrected sources list.
chipkent Dec 5, 2023
6e83ad0
Address review comments. Improved documentation.
chipkent Dec 5, 2023
0f08c74
Address review comments. Compute time range nanos on demand and supp…
chipkent Dec 6, 2023
282e6ea
Address review comments. More explicitly handle open vs closed ranges.
chipkent Dec 6, 2023
f5b355c
Address review comments. More explicitly handle open vs closed ranges.
chipkent Dec 6, 2023
d5e7e23
Address review comments. Update calendar parsing for 24:00.
chipkent Dec 6, 2023
bfb96fb
Spotless
chipkent Dec 6, 2023
f25ebce
Addressing review comments. Add methods that return durations.
chipkent Dec 6, 2023
2665407
Addressing review comments. Add methods that return durations.
chipkent Dec 6, 2023
3669b5e
Fixed error message.
chipkent Dec 11, 2023
7aad38a
Addressing reviewer comments. Making the calendar API null tolerant,…
chipkent Dec 11, 2023
547d7a6
Addressing review comments. Make the entire API null tolerant for co…
chipkent Dec 12, 2023
1a2e925
Addressing review comments. Defer calendar initialization to make fi…
chipkent Dec 12, 2023
b59a737
Spotless
chipkent Dec 12, 2023
789b826
Address review comments. Rename DateTimeUtils.plus to DateTimeUtils.…
chipkent Dec 12, 2023
1ffdb7d
Update py/server/deephaven/calendar.py
chipkent Dec 13, 2023
1297b99
Address review comments. Rename DateTimeUtils.minus to DateTimeUtils…
chipkent Dec 15, 2023
40d2a6c
Merge remote-tracking branch 'origin/cal_upgrades' into cal_upgrades
chipkent Dec 15, 2023
1f5d28d
Address review comments. Docstring cleanup.
chipkent Dec 15, 2023
787b646
Address review comments. BusinessCalendarXMLParser not public.
chipkent Dec 15, 2023
a007d3f
Address review comments. Made BusinessCalendar and Calendar construc…
chipkent Dec 15, 2023
a0618b3
Address review comments. Shrink the UTC calendar to save memory.
chipkent Dec 15, 2023
48a4a13
Address review comments. Rename dayOfWeek to dayOfWeekValue and add …
chipkent Dec 15, 2023
91d0168
Address review comments. Compromise on publishing business calendars…
chipkent Dec 15, 2023
ec5a419
Address review comments. Fix javadocs.
chipkent Dec 15, 2023
6131056
Rebase
chipkent Dec 15, 2023
2133a93
Address review comments. Spotless
chipkent Dec 15, 2023
81aca2a
Python unit test fixes.
chipkent Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Generators/Generators.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,25 @@ task groovyStaticImportGeneratorAssert(type: JavaExec, dependsOn: 'classes') {
classpath = sourceSets.main.runtimeClasspath
workingDir = workDir
onlyIf { System.getenv('NO_ASSERT') != 'true' }
}

task generateStaticCalendarMethods(type: JavaExec, dependsOn: 'classes') {
description 'Run StaticCalendarMethodsGenerator'

main = 'io.deephaven.libs.StaticCalendarMethodsGenerator'
args devRoot, 'false'
classpath = sourceSets.main.runtimeClasspath
workingDir = workDir
}

task generateStaticCalendarMethodsAssert(type: JavaExec, dependsOn: 'classes') {
description 'Run StaticCalendarMethodsGenerator to assert that the generated code has not changed'

main = 'io.deephaven.libs.StaticCalendarMethodsGenerator'
args devRoot, 'true'
classpath = sourceSets.main.runtimeClasspath
workingDir = workDir
onlyIf { System.getenv('NO_ASSERT') != 'true' }
}

task generateAxesPlotMethods(type: JavaExec, dependsOn: 'classes') {
Expand Down Expand Up @@ -190,6 +208,7 @@ tasks.register 'generateAllPythonAssert', {

tasks.register 'generateAll', {
Task t -> t.dependsOn ':Generators:groovyStaticImportGenerator',
':Generators:generateStaticCalendarMethods',
':Generators:generateAxesPlotMethods',
':Generators:generateMultiSeries',
':Generators:generateFigureImmutable',
Expand All @@ -201,6 +220,7 @@ tasks.register 'generateAll', {
}

project.tasks.getByName('quick').dependsOn groovyStaticImportGeneratorAssert,
generateStaticCalendarMethodsAssert,
generateAxesPlotMethodsAssert,
generateMultiSeriesAssert,
generateFigureImmutableAssert,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/**
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.gen;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Abstract class for generating Java code from methods of one or more classes.
chipkent marked this conversation as resolved.
Show resolved Hide resolved
*
* {@link #generateCode()} must be called to generate the code.
*/
public abstract class AbstractBasicJavaGenerator {
private static final Logger log = Logger.getLogger(AbstractBasicJavaGenerator.class.toString());

private final String gradleTask;
private final String packageName;
private final String className;
private final Map<JavaFunction, JavaFunction> functions = new TreeMap<>();
private final Collection<Predicate<JavaFunction>> skipsGen;

/**
* Constructor.
*
* @param gradleTask Gradle task to generate the code.
* @param packageName Package name for the generated class.
* @param className Class name for the generated class.
* @param imports Array of fully qualified class names to process.
* @param includeMethod a predicate to determine if a method should be considered for code generation.
* @param skipsGen Collection of predicates to determine if a function should be skipped when generating code.
* @throws ClassNotFoundException If a class in the imports array cannot be found.
*/
public AbstractBasicJavaGenerator(final String gradleTask, final String packageName, final String className,
final String[] imports, Predicate<Method> includeMethod, Collection<Predicate<JavaFunction>> skipsGen)
throws ClassNotFoundException {
this.gradleTask = gradleTask;
this.packageName = packageName;
this.className = className;
this.skipsGen = skipsGen;

for (String imp : imports) {
Class<?> c = Class.forName(imp, false, Thread.currentThread().getContextClassLoader());
log.info("Processing class: " + c);

for (Method m : c.getMethods()) {
log.info("Processing method (" + c + "): " + m);
if (includeMethod.test(m)) {
addMethod(m);
}
}
}
}

private void addMethod(Method m) {
log.info("Processing public static method: " + m);

JavaFunction f = new JavaFunction(m);
// System.out.println(f);

if (functions.containsKey(f)) {
JavaFunction fAlready = functions.get(f);
final String message = "Signature Already Present: " + fAlready + "\t" + f;
log.severe(message);
throw new RuntimeException(message);
} else {
log.info("Added method: " + f);
functions.put(f, f);
}
}

/**
* Generate Javadoc for the output class.
*
* @return The Javadoc.
*/
abstract public String generateClassJavadoc();

/**
* Generate the Java code for a function.
*
* @param f The function.
* @return The Java code.
*/
abstract public String generateFunction(JavaFunction f);

/**
* Generate the code.
*
* @return The generated code.
*/
@SuppressWarnings("StringConcatenationInLoop")
public String generateCode() {

String code = GenUtils.javaHeader(this.getClass(), gradleTask);
code += "package " + packageName + ";\n\n";

Set<String> imports = GenUtils.typesToImport(functions.keySet());

for (String imp : imports) {
code += "import " + imp + ";\n";
}

code += "\n";
code += generateClassJavadoc();
code += "public class " + className + " {\n";

for (JavaFunction f : functions.keySet()) {
boolean skip = false;
for (Predicate<JavaFunction> skipCheck : skipsGen) {
skip = skip || skipCheck.test(f);
}

if (skip) {
log.warning("*** Skipping function: " + f);
continue;
}

code += generateFunction(f);
code += "\n";
}

code += "}\n\n";

return code;
}

/**
* Run a generator from the command line.
*
* @param gen The generator to run.
* @param relativeFilePath The relative file path to write the generated code to.
* @param args The command line arguments.
* @throws IOException If there is an IO error.
*/
public static void runCommandLine(final AbstractBasicJavaGenerator gen, final String relativeFilePath,
final String[] args) throws IOException {

String devroot = null;
boolean assertNoChange = false;
if (args.length == 1) {
devroot = args[0];
} else if (args.length == 2) {
devroot = args[0];
assertNoChange = Boolean.parseBoolean(args[1]);
} else {
System.out.println("Usage: <devroot> [assertNoChange]");
System.exit(-1);
}

log.setLevel(Level.WARNING);
log.warning("Running " + gen.getClass().getSimpleName() + " assertNoChange=" + assertNoChange);

final String code = gen.generateCode();
log.info("\n\n**************************************\n\n");
log.info(code);

String file = devroot + relativeFilePath;

if (assertNoChange) {
String oldCode = new String(Files.readAllBytes(Paths.get(file)));
GenUtils.assertGeneratedCodeSame(AbstractBasicJavaGenerator.class, gen.gradleTask, oldCode, code);
} else {

PrintWriter out = new PrintWriter(file);
out.print(code);
out.close();

log.warning("Class file written to: " + file);
}
}

}
Loading
Loading