Skip to content

Commit

Permalink
Merge branch 'hotfix/1.11.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Jul 31, 2024
2 parents d007315 + af89f86 commit c12a769
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.18
1.11.19
8 changes: 4 additions & 4 deletions src/metkit/mars/MarsLanguage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ static bool isnumeric(const std::string& s) {
}

std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::string& name,
const std::vector<std::string>& values, bool fail, bool quiet,
const std::vector<std::string>& values, bool fail, bool quiet, bool fullMatch,
const std::map<std::string, std::string>& aliases) {
size_t score = 1;
size_t score = (fullMatch ? name.length() : 1);
std::vector<std::string> best;

static bool strict = eckit::Resource<bool>("$METKIT_LANGUAGE_STRICT_MODE", false);
Expand Down Expand Up @@ -282,7 +282,7 @@ std::string MarsLanguage::expandVerb(const MarsExpandContext& ctx, const std::st
// }

// return cache_[verb] = bestMatch(verb, verbs_, true);
return bestMatch(ctx, verb, verbs_, true, true);
return bestMatch(ctx, verb, verbs_, true, true, false);
}

class TypeHidden : public Type {
Expand Down Expand Up @@ -325,7 +325,7 @@ MarsRequest MarsLanguage::expand(const MarsExpandContext& ctx, const MarsRequest
p = (*c).second;
}
else {
p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, aliases_);
p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, false, aliases_);
}

// if (seen.find(p) != seen.end()) {
Expand Down
1 change: 1 addition & 0 deletions src/metkit/mars/MarsLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MarsLanguage : private eckit::NonCopyable {
const std::vector<std::string>& values,
bool fail,
bool quiet,
bool fullMatch,
const StringMap& aliases = StringMap());

static eckit::Value jsonFile(const std::string& name);
Expand Down
2 changes: 1 addition & 1 deletion src/metkit/mars/TypeEnum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool TypeEnum::expand(const MarsExpandContext& ctx, std::string& value) const {
return true;
}

std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, mapping_);
std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, false, mapping_);
if (v.empty()) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/metkit/mars/TypeParam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,12 @@ std::string Rule::lookup(const MarsExpandContext& ctx, const std::string & s, bo

ChainedContext c(ctx, *this);

std::string paramid = metkit::mars::MarsLanguage::bestMatch(c, s, values_, false, false, mapping_);
std::string paramid = metkit::mars::MarsLanguage::bestMatch(c, s, values_, false, false, true, mapping_);
if (!paramid.empty()) {
return paramid;
}
return metkit::mars::MarsLanguage::bestMatch(c, s, defaultValues_, fail, false, defaultMapping_);

return metkit::mars::MarsLanguage::bestMatch(c, s, defaultValues_, fail, false, false, defaultMapping_);
}

static std::vector<Rule>* rules = nullptr;
Expand Down Expand Up @@ -436,7 +437,7 @@ static void init() {

std::set<std::string> shortnames;
std::set<std::string> associatedIDs;

const eckit::Value pc = eckit::YAMLParser::decodeFile(LibMetkit::shortnameContextYamlFile());
ASSERT(pc.isList());

Expand All @@ -446,11 +447,10 @@ static void init() {

for (size_t i=0; i < keys.size(); i++) {
auto el = ids.element(keys[i]);
ASSERT(el.size() > 0);
auto val = el[0];

if (shortnames.find(val) != shortnames.end()) {
associatedIDs.emplace(keys[i]);
for (size_t j=0; j < el.size(); j++) {
if (shortnames.find(el[j]) != shortnames.end()) {
associatedIDs.emplace(keys[i]);
}
}
}

Expand Down
58 changes: 58 additions & 0 deletions tests/test_expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,64 @@ CASE( "test_metkit_expand_param" ) {
EXPECT_EQUAL(params[4], "164");
EXPECT_EQUAL(params[5], "228");
}
{
const char* text = "retrieve,class=od,expver=1,stream=msmm,date=-1,time=0000,type=em,levtype=sfc,step=24,param=e";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 1);

EXPECT_EQUAL(params[0], "172182");
}
{
const char* text = "retrieve,class=od,expver=1,stream=msmm,date=-1,time=0000,type=em,levtype=sfc,step=24,param=e/erate";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 2);

EXPECT_EQUAL(params[0], "172182");
EXPECT_EQUAL(params[1], "172182");
}
{
const char* text = "retrieve,class=od,expver=1,stream=enwh,date=-1,time=0000,type=pf,levtype=sfc,step=24,param=sh10";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 1);

EXPECT_EQUAL(params[0], "140120");
}
{
const char* text = "retrieve,class=od,expver=1,stream=enwh,date=-1,time=0000,type=pf,levtype=sfc,step=24,param=p1ww";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 1);

EXPECT_EQUAL(params[0], "140223");
}
{
const char* text = "retrieve,class=od,expver=1,stream=waef,date=-1,time=0000,type=cf,levtype=sfc,step=24,param=WSK/MWP";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 2);

EXPECT_EQUAL(params[0], "140252");
EXPECT_EQUAL(params[1], "140232");
}
{
const char* text = "retrieve,class=od,expver=1,stream=eefo,date=-1,time=0000,type=fcmean,levtype=sfc,step=24,param=MSL";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 1);

EXPECT_EQUAL(params[0], "151");
}
{
const char* text = "retrieve,class=od,expver=1,stream=eefo,date=-1,time=0000,type=fcmean,levtype=sfc,step=24,param=strda";
MarsRequest r = MarsRequest::parse(text);
auto params = r.values("param");
EXPECT_EQUAL(params.size(), 1);

EXPECT_EQUAL(params[0], "171175");
}
}

//-----------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions tests/test_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ namespace test {

CASE( "test_request_json" ) {
{
const char* text = "retrieve,class=od,expver=0079,stream=enfh,date=-1,time=00/12,type=fcmean,levtype=sfc,step=24,number=1/to/2,param=mucin/mucape/tprate";
const char* text = "retrieve,class=od,expver=0079,stream=enfh,date=20240729,time=00/12,type=fcmean,levtype=sfc,step=24,number=1/to/2,param=mucin/mucape/tprate";
MarsRequest r = MarsRequest::parse(text);
{
std::stringstream ss;
eckit::JSON plain(ss);
r.json(plain);
// std::cout << ss.str() << std::endl;
std::cout << ss.str() << std::endl;
EXPECT_EQUAL(ss.str(), "{\"class\":\"od\",\"expver\":\"0079\",\"stream\":\"enfh\",\"date\":\"20240729\",\"time\":[\"0000\",\"1200\"],\"type\":\"fcmean\",\"levtype\":\"sfc\",\"step\":\"24\",\"number\":[\"1\",\"2\"],\"param\":[\"228236\",\"228235\",\"172228\"],\"domain\":\"g\"}");
}
{
Expand All @@ -52,7 +52,7 @@ CASE( "test_request_json" ) {
}
}
{
const char* text = "retrieve,class=od,expver=1,stream=wave,date=-1,time=00,type=an,levtype=sfc,step=24,param=2dfd ";
const char* text = "retrieve,class=od,expver=1,stream=wave,date=20240729,time=00,type=an,levtype=sfc,step=24,param=2dfd ";
MarsRequest r = MarsRequest::parse(text);
{
std::stringstream ss;
Expand Down

0 comments on commit c12a769

Please sign in to comment.