Skip to content

Commit

Permalink
Merge pull request #84 from kuanshi/master
Browse files Browse the repository at this point in the history
kz - adding new features in EVT and fixing the motion in the example eeuq-0002
  • Loading branch information
fmckenna authored Oct 1, 2021
2 parents 0607762 + 13bad49 commit db65fec
Show file tree
Hide file tree
Showing 9 changed files with 2,249 additions and 170 deletions.
113 changes: 94 additions & 19 deletions EVENTS/peerNGA/PEER_NGA_Records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,80 @@ void PEER_NGA_Records::setupUI(GeneralInformationWidget* generalInfoWidget)
nRecordsEditBox->setValidator(positiveIntegerValidator);
recordSelectionLayout->addWidget(nRecordsEditBox, 0, 1);

// Fault Type
faultTypeBox = new QComboBox();
faultTypeBox->addItem("All Types");
faultTypeBox->addItem("Strike Slip (SS)");
faultTypeBox->addItem("Normal/Oblique");
faultTypeBox->addItem("Reverse/Oblique");
faultTypeBox->addItem("SS+Normal");
faultTypeBox->addItem("SS+Reverse");
faultTypeBox->addItem("Normal+Reverse");
recordSelectionLayout->addWidget(new QLabel("Fault Type"), 1, 0);
recordSelectionLayout->addWidget(faultTypeBox, 1, 1);

// Pulse Type
pulseBox = new QComboBox();
pulseBox->addItem("All");
pulseBox->addItem("Only Pulse-like");
pulseBox->addItem("No Pulse-like");
recordSelectionLayout->addWidget(new QLabel("Pulse"), 2, 0);
recordSelectionLayout->addWidget(pulseBox, 2, 1);

//Magnitude Range
magnitudeCheckBox = new QCheckBox("Magnitude");
recordSelectionLayout->addWidget(magnitudeCheckBox, 1, 0);
recordSelectionLayout->addWidget(magnitudeCheckBox, 3, 0);
magnitudeMin = new QLineEdit("5.0");
magnitudeMin->setEnabled(false);
magnitudeMin->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(magnitudeMin, 1, 1);
recordSelectionLayout->addWidget(magnitudeMin, 3, 1);
magnitudeMax = new QLineEdit("8.0");
magnitudeMax->setEnabled(false);
magnitudeMax->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(magnitudeMax, 1, 2);
recordSelectionLayout->addWidget(magnitudeMax, 3, 2);

distanceCheckBox = new QCheckBox("Distance");
recordSelectionLayout->addWidget(distanceCheckBox, 2, 0);
recordSelectionLayout->addWidget(distanceCheckBox, 4, 0);
distanceMin = new QLineEdit("0.0");
distanceMin->setEnabled(false);
distanceMin->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(distanceMin, 2, 1);
recordSelectionLayout->addWidget(distanceMin, 4, 1);
distanceMax = new QLineEdit("50.0");
distanceMax->setEnabled(false);
distanceMax->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(distanceMax, 2, 2);
recordSelectionLayout->addWidget(new QLabel("km"), 2, 3);
recordSelectionLayout->addWidget(distanceMax, 4, 2);
recordSelectionLayout->addWidget(new QLabel("km"), 4, 3);

vs30CheckBox = new QCheckBox("Vs30");
recordSelectionLayout->addWidget(vs30CheckBox, 3, 0);
recordSelectionLayout->addWidget(vs30CheckBox, 5, 0);
vs30Min = new QLineEdit("150.0");
vs30Min->setEnabled(false);
vs30Min->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(vs30Min, 3, 1);
recordSelectionLayout->addWidget(vs30Min, 5, 1);
vs30Max = new QLineEdit("300.0");
vs30Max->setEnabled(false);
vs30Max->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(vs30Max, 3, 2);
recordSelectionLayout->addWidget(new QLabel("m/s"), 3, 3);
recordSelectionLayout->addWidget(vs30Max, 5, 2);
recordSelectionLayout->addWidget(new QLabel("m/s"), 5, 3);

durationCheckBox = new QCheckBox("D5-95");
recordSelectionLayout->addWidget(durationCheckBox, 6, 0);
durationMin = new QLineEdit("0.0");
durationMin->setEnabled(false);
durationMin->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(durationMin, 6, 1);
durationMax = new QLineEdit("20.0");
durationMax->setEnabled(false);
durationMax->setValidator(positiveDoubleValidator);
recordSelectionLayout->addWidget(durationMax, 6, 2);
recordSelectionLayout->addWidget(new QLabel("sec"), 6, 3);

//#ifdef _WIN32
// targetSpectrumGroup->setMaximumHeight(200);
// recordSelectionGroup->setMaximumHeight(200);
//#else
targetSpectrumLayout->setRowStretch(2,1);
recordSelectionLayout->setRowStretch(4, 1);
recordSelectionLayout->setRowStretch(7, 1);
//#endif

auto scalingGroup = new QGroupBox("Scaling/Selection Criteria");
Expand Down Expand Up @@ -198,18 +230,25 @@ void PEER_NGA_Records::setupUI(GeneralInformationWidget* generalInfoWidget)
groundMotionsComponentsBox->addItem("H2", GroundMotionComponents::One);
groundMotionsComponentsBox->addItem("V", GroundMotionComponents::Three);

// Suite Averge
suiteAverageBox = new QComboBox();
suiteAverageBox->addItem("Arithmetic");
suiteAverageBox->addItem("Geometric");

groundMotionsLayout->addWidget(new QLabel("Acceleration Components"), 0, 0);
groundMotionsLayout->addWidget(groundMotionsComponentsBox, 0, 1);
groundMotionsLayout->addWidget(new QLabel("Suite Average"), 1, 0);
groundMotionsLayout->addWidget(suiteAverageBox, 1, 1);
recordsTable->setMinimumHeight(200);
groundMotionsLayout->addWidget(recordsTable, 1, 0, 1, 2);
groundMotionsLayout->setRowStretch(1, 1);
groundMotionsLayout->addWidget(recordsTable, 2, 0, 1, 2);
groundMotionsLayout->setRowStretch(2, 1);

progressBar = new QProgressBar();
progressBar->setRange(0,0);
progressBar->setAlignment(Qt::AlignCenter);
progressBar->setHidden(true);

groundMotionsLayout->addWidget(progressBar, 2, 0, 1, 2);
groundMotionsLayout->addWidget(progressBar, 3, 0, 1, 2);

layout->addWidget(targetSpectrumGroup, 0, 0);
layout->addWidget(recordSelectionGroup, 0, 1);
Expand Down Expand Up @@ -290,6 +329,11 @@ void PEER_NGA_Records::setupConnections()
vs30Max->setEnabled(checked);
});

connect(durationCheckBox, &QCheckBox::clicked, this, [this](bool checked){
durationMin->setEnabled(checked);
durationMax->setEnabled(checked);
});

connect(&peerClient, &PeerNgaWest2Client::statusUpdated, this, &PEER_NGA_Records::updateStatus);

connect(&peerClient, &PeerNgaWest2Client::selectionStarted, this, [this]()
Expand Down Expand Up @@ -453,6 +497,10 @@ void PEER_NGA_Records::selectRecords()
if(vs30CheckBox->checkState() == Qt::Checked)
vs30Range.setValue(qMakePair(vs30Min->text().toDouble(), vs30Max->text().toDouble()));

QVariant durationRange;
if(durationCheckBox->checkState() == Qt::Checked)
durationRange.setValue(qMakePair(durationMin->text().toDouble(), durationMax->text().toDouble()));

if(targetSpectrumDetails->currentIndex() == 0)
{
auto asce710widget = reinterpret_cast<ASCE710Target*>(targetSpectrumDetails->currentWidget());
Expand All @@ -462,7 +510,7 @@ void PEER_NGA_Records::selectRecords()
nRecordsEditBox->text().toInt(),
magnitudeRange,
distanceRange,
vs30Range,groundMotionsComponentsBox->currentIndex()+1);
vs30Range,durationRange,groundMotionsComponentsBox->currentIndex()+1,suiteAverageBox->currentIndex(),faultTypeBox->currentIndex()+1,pulseBox->currentIndex()+1);
}
else
{
Expand All @@ -476,7 +524,8 @@ void PEER_NGA_Records::selectRecords()
auto spectrum = userTargetWidget->spectrum();

if (spectrum.size() > 0)
peerClient.selectRecords(userTargetWidget->spectrum(), nRecordsEditBox->text().toInt(), magnitudeRange, distanceRange, vs30Range, groundMotionsComponentsBox->currentIndex()+1);
peerClient.selectRecords(userTargetWidget->spectrum(), nRecordsEditBox->text().toInt(), magnitudeRange, distanceRange, vs30Range, durationRange,
groundMotionsComponentsBox->currentIndex()+1, suiteAverageBox->currentIndex(), faultTypeBox->currentIndex()+1, pulseBox->currentIndex()+1);
else
{
progressBar->setHidden("True");
Expand Down Expand Up @@ -630,7 +679,14 @@ bool PEER_NGA_Records::outputToJSON(QJsonObject &jsonObject)
spectrumJson["SpectrumType"] = spectrumTypeComboBox->currentText();
jsonObject["TargetSpectrum"] = spectrumJson;

jsonObject["scaling"] = scalingComboBox->currentText();
jsonObject["singlePeriod"] = scalingPeriodLineEdit->text();
jsonObject["periodPoints"] = periodPointsLineEdit->text();
jsonObject["weights"] = weightsLineEdit->text();

jsonObject["components"] = groundMotionsComponentsBox->currentText();
jsonObject["faultType"] = faultTypeBox->currentText();
jsonObject["pulse"] = pulseBox->currentText();

jsonObject["records"] = nRecordsEditBox->text();

Expand All @@ -646,6 +702,11 @@ bool PEER_NGA_Records::outputToJSON(QJsonObject &jsonObject)
jsonObject["vs30Min"] = vs30Min->text();
jsonObject["vs30Max"] = vs30Max->text();

jsonObject["durationRange"] = durationCheckBox->isChecked();
jsonObject["durationMin"] = durationMin->text();
jsonObject["durationMax"] = durationMax->text();


return true;
}

Expand All @@ -658,7 +719,14 @@ bool PEER_NGA_Records::inputFromJSON(QJsonObject &jsonObject)
dynamic_cast<AbstractJsonSerializable*>(targetSpectrumDetails->currentWidget())->deserialize(jsonObject["TargetSpectrum"].toObject());
}

scalingComboBox->setCurrentText(jsonObject["scaling"].toString());
scalingPeriodLineEdit->setText(jsonObject["singlePeriod"].toString());
periodPointsLineEdit->setText(jsonObject["periodPoints"].toString());
weightsLineEdit->setText(jsonObject["weights"].toString());

groundMotionsComponentsBox->setCurrentText(jsonObject["components"].toString());
faultTypeBox->setCurrentText(jsonObject["faultType"].toString());
pulseBox->setCurrentText(jsonObject["pulse"].toString());

nRecordsEditBox->setText(jsonObject["records"].toString());

Expand All @@ -678,11 +746,18 @@ bool PEER_NGA_Records::inputFromJSON(QJsonObject &jsonObject)

auto vs30Range = jsonObject["vs30Range"].toBool();
vs30CheckBox->setChecked(vs30Range);
vs30Min->setEnabled(distanceRange);
vs30Min->setEnabled(vs30Range);
vs30Min->setText(jsonObject["vs30Min"].toString());
vs30Max->setEnabled(distanceRange);
vs30Max->setEnabled(vs30Range);
vs30Max->setText(jsonObject["vs30Max"].toString());

auto durationRange = jsonObject["durationRange"].toBool();
durationCheckBox->setChecked(durationRange);
durationMin->setEnabled(durationMin);
durationMin->setText(jsonObject["durationMin"].toString());
durationMax->setEnabled(durationRange);
durationMax->setText(jsonObject["durationMax"].toString());

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions EVENTS/peerNGA/PEER_NGA_Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public slots:
QComboBox* spectrumTypeComboBox;
QStackedWidget* targetSpectrumDetails;
QGridLayout* recordSelectionLayout;
QComboBox* suiteAverageBox; // how to compute the suite average
QComboBox* faultTypeBox; // fault type in PEER record searching
QComboBox* pulseBox; // whether filtering records by pulse-like feature

//Magnitude Range
QCheckBox* magnitudeCheckBox;
Expand All @@ -93,6 +96,11 @@ public slots:
QLineEdit* vs30Max;
QTemporaryDir groundMotionsFolder;

//D5-95 Range
QCheckBox* durationCheckBox;
QLineEdit* durationMin;
QLineEdit* durationMax;

//Scaling
QComboBox* scalingComboBox;
QLabel* scalingPeriodLabel1;
Expand Down
22 changes: 20 additions & 2 deletions EVENTS/peerNGA/PeerNgaWest2Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void PeerNgaWest2Client::signIn(QString username, QString password)
signInPageReply = networkManager.get(peerSignInPageRequest);
}

void PeerNgaWest2Client::selectRecords(QList<QPair<double, double>> spectrum, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, int peerSRkey)
void PeerNgaWest2Client::selectRecords(QList<QPair<double, double>> spectrum, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, QVariant durationRange, int peerSRkey, int peerSRmeanFlag, int peerFaultType, int peerPulse)
{
emit selectionStarted();
emit statusUpdated("Performing Record Selection...");
Expand All @@ -51,7 +51,12 @@ void PeerNgaWest2Client::selectRecords(QList<QPair<double, double>> spectrum, in
this->magnitudeRange = magnitudeRange;
this->distanceRange = distanceRange;
this->vs30Range = vs30Range;
this->durationRange = durationRange;
this->SRkey = peerSRkey;
this->SRmeanFlag = peerSRmeanFlag;
this->faultType = peerFaultType;
this->pulse = peerPulse;


uploadFileRequest.setUrl(QUrl("https://ngawest2.berkeley.edu/spectras/uploadFile"));
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
Expand Down Expand Up @@ -88,13 +93,16 @@ void PeerNgaWest2Client::selectRecords(QList<QPair<double, double>> spectrum, in
uploadFileReply = networkManager.post(uploadFileRequest, multiPart);
}

void PeerNgaWest2Client::selectRecords(double sds, double sd1, double tl, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, int peerSRkey)
void PeerNgaWest2Client::selectRecords(double sds, double sd1, double tl, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, QVariant durationRange, int peerSRkey, int peerSRmeanFlag, int peerFaultType, int peerPulse)
{
emit selectionStarted();
emit statusUpdated("Performing Record Selection...");

this->nRecords = nRecords;
this->SRkey = peerSRkey;
this->SRmeanFlag = peerSRmeanFlag;
this->faultType = peerFaultType;
this->pulse = peerPulse;

QNetworkCookie cookie("SpectrumModel_Dropdown", "99");
cookie.setDomain("ngawest2.berkeley.edu");
Expand All @@ -119,6 +127,7 @@ void PeerNgaWest2Client::selectRecords(double sds, double sd1, double tl, int nR
this->magnitudeRange = magnitudeRange;
this->distanceRange = distanceRange;
this->vs30Range = vs30Range;
this->durationRange = durationRange;

recordsToDownload.clear();
postSpectraReply = networkManager.post(postSpectraRequest, postSpectraParameters.query().toUtf8());
Expand Down Expand Up @@ -353,6 +362,9 @@ void PeerNgaWest2Client::processPostSpectrumReply()
params.addQueryItem("authenticity_token", authenticityToken);
params.addQueryItem("search[DampingRatio]", "0.05");
params.addQueryItem("search[SRkey]", QString::number(this->SRkey));
params.addQueryItem("search[SRmeanFlag]", QString::number(this->SRmeanFlag));
params.addQueryItem("search[faultType]", QString::number(this->faultType));
params.addQueryItem("search[pulse]", QString::number(this->pulse));
params.addQueryItem("search[search_station_name]", "");
params.addQueryItem("search[search_eq_name]", "");

Expand Down Expand Up @@ -404,6 +416,12 @@ void PeerNgaWest2Client::processPostSpectrumReply()
QString vs30 = QString::number(vs30Pair.first) + ',' + QString::number(vs30Pair.second);
params.addQueryItem("search[vs30]", vs30);
}
if(durationRange.isValid() && !durationRange.isNull())
{
auto durationPair = durationRange.value<QPair<double, double>>();
QString duration = QString::number(durationPair.first) + ',' + QString::number(durationPair.second);
params.addQueryItem("search[duration]", duration);
}
} else {

// just want to download specific records
Expand Down
8 changes: 6 additions & 2 deletions EVENTS/peerNGA/PeerNgaWest2Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class PeerNgaWest2Client : public QObject
explicit PeerNgaWest2Client(QObject *parent = nullptr);
bool loggedIn();
void signIn(QString username, QString password);
void selectRecords(double sds, double sd1, double tl, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, int peerSRkey);
void selectRecords(QList<QPair<double, double>> spectrum, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, int peerSRkey);
void selectRecords(double sds, double sd1, double tl, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, QVariant durationRange, int peerSRkey, int peerSRmeanFlag, int peerFaultType, int peerPulse);
void selectRecords(QList<QPair<double, double>> spectrum, int nRecords, QVariant magnitudeRange, QVariant distanceRange, QVariant vs30Range, QVariant durationRange, int peerSRkey, int peerSRmeanFlag, int peerFaultType, int peerPulse);
void selectRecords(QStringList);

void setScalingParameters(const int scaleFlag,
Expand Down Expand Up @@ -52,10 +52,14 @@ public slots:
QString password;
int nRecords;
int SRkey;
int SRmeanFlag;
int faultType;
int pulse;
bool isLoggedIn;
QVariant magnitudeRange;
QVariant distanceRange;
QVariant vs30Range;
QVariant durationRange;

int searchScaleFlag;
QString searchPeriodPoints;
Expand Down
Loading

0 comments on commit db65fec

Please sign in to comment.