Skip to content

Commit

Permalink
Replace calls to performance API with LAMP data (Version 4.1) (#976)
Browse files Browse the repository at this point in the history
* Replace calls to performance API with LAMP data

* Mark performance API usage as deprecated

* Update datadog layer

* Using v3 alerts

* Removing all performance API code

* Show all alerts relevant to charts

* Handle empty alert headers

* Bump version to 4.1.0

* Remove V2 API key

* Upping v3 alert date

* Update v3 api key description

* Use new travel time name for LAMP

* Only include benchmarks longer than 1sec

* Fixing benchmark data
  • Loading branch information
devinmatte authored May 12, 2024
1 parent 2484af2 commit f2a9553
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 881 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TM_FRONTEND_CERT_ARN: ${{ secrets.TM_FRONTEND_CERT_ARN }}
TM_LABS_WILDCARD_CERT_ARN: ${{ secrets.TM_LABS_WILDCARD_CERT_ARN }}
MBTA_V2_API_KEY: ${{ secrets.MBTA_V2_API_KEY }}
MBTA_V3_API_KEY: ${{ secrets.MBTA_V3_API_KEY }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}

steps:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ This is the repository for the TransitMatters Data Dashboard. Client code is wri

## Development Instructions

1. Add `MBTA_V2_API_KEY` and `MBTA_V3_API_KEY` to your shell environment:
- `export MBTA_V2_API_KEY='KEY'` in ~/.bashrc or ~/.zshrc
1. Add `MBTA_V3_API_KEY` to your shell environment:
- `export MBTA_V3_API_KEY='KEY'` in ~/.bashrc or ~/.zshrc
2. Add your AWS credentials (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) to your shell environment, OR add them to a .boto config file with awscli command `aws configure`.
3. In the root directory, run `npm install` to install all frontend and backend dependencies
Expand Down
15 changes: 8 additions & 7 deletions common/components/charts/SingleDayLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { watermarkLayout } from '../../constants/charts';
import { writeError } from '../../utils/chartError';
import { getFormattedTimeString } from '../../utils/time';
import { AlertsDisclaimer } from '../general/AlertsDisclaimer';
import { FIVE_MINUTES } from '../../constants/time';
import { LegendSingleDay } from './Legend';
import { ChartDiv } from './ChartDiv';
import { ChartBorder } from './ChartBorder';
Expand Down Expand Up @@ -93,14 +94,14 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({

// Format benchmark data if it exists.
const benchmarkData = data.map((datapoint) =>
benchmarkField && datapoint[benchmarkField] ? datapoint[benchmarkField] : undefined
benchmarkField && datapoint[benchmarkField] ? datapoint[benchmarkField] : null
);
const displayBenchmarkData = benchmarkData.every((datapoint) => datapoint !== undefined);
// Have to use `as number` because typescript doesn't understand `datapoint` is not undefined.
const displayBenchmarkData = benchmarkData.some((datapoint) => datapoint !== null);

const multiplier = units === 'Minutes' ? 1 / 60 : 1;
const benchmarkDataFormatted = displayBenchmarkData
? benchmarkData.map((datapoint) => ((datapoint as number) * multiplier).toFixed(2))
: null;
const benchmarkDataFormatted = benchmarkData
.map((datapoint) => (datapoint ? (datapoint * multiplier).toFixed(2) : null))
.filter((datapoint) => datapoint !== null);

const convertedData = data.map((datapoint) =>
((datapoint[metricField] as number) * multiplier).toFixed(2)
Expand Down Expand Up @@ -225,7 +226,7 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
const today = new Date(`${date}T00:00:00`);
const low = new Date(today);
low.setHours(6);
axis.min = Math.min(axis.min, low.valueOf());
axis.min = Math.min(axis.min - FIVE_MINUTES, low.valueOf());
const high = new Date(today);
high.setDate(high.getDate() + 1);
high.setHours(1);
Expand Down
2 changes: 1 addition & 1 deletion common/types/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface SingleDayDataPoint {
headway_time_sec?: number;
dwell_time_sec?: number;
benchmark_travel_time_sec?: number;
benchmark_headway_time_sec?: number;
benchmark_headway_time_sec?: number | null;
threshold_flag_1?: string;
speed_mph?: number;
benchmark_speed_mph?: number;
Expand Down
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ while getopts "pc" opt; do
done

# Ensure required secrets are set
if [[ -z "$MBTA_V2_API_KEY" || -z "$DD_API_KEY" ]]; then
echo "Must provide MBTA_V2_API_KEY and DD_API_KEY in environment to deploy" 1>&2
if [[ -z "$MBTA_V3_API_KEY" || -z "$DD_API_KEY" ]]; then
echo "Must provide MBTA_V3_API_KEY and DD_API_KEY in environment to deploy" 1>&2
exit 1
elif [ -z "$TM_FRONTEND_CERT_ARN" ] && [ -z "$TM_LABS_WILDCARD_CERT_ARN" ]; then
echo "Must provide TM_FRONTEND_CERT_ARN or TM_LABS_WILDCARD_CERT_ARN in environment to deploy" 1>&2
Expand Down Expand Up @@ -98,7 +98,7 @@ aws cloudformation deploy --template-file cfn/packaged.yaml --stack-name $CF_STA
TMBackendCertArn=$BACKEND_CERT_ARN \
TMBackendHostname=$BACKEND_HOSTNAME \
TMBackendZone=$BACKEND_ZONE \
MbtaV2ApiKey=$MBTA_V2_API_KEY \
MbtaV3ApiKey=$MBTA_V3_API_KEY \
DDApiKey=$DD_API_KEY \
GitVersion=$GIT_VERSION \
DDTags=$DD_TAGS
Expand Down
Loading

0 comments on commit f2a9553

Please sign in to comment.