Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0cf7cbb
Update Getting Started: Create and Manage Cloud Resources: Challenge
vickyjnv Oct 8, 2020
b6b37fe
Merge pull request #16 from rahullrajesh/rahullrajesh-patch-1
rahullrajesh Oct 9, 2020
20c5bff
Update analyze-images.py
KevzPeter Oct 10, 2020
6f5d9c0
Merge pull request #14 from vickyjnv/master
rahullrajesh Oct 14, 2020
aa27134
Merge pull request #17 from KevzPeter/patch-1
rahullrajesh Oct 14, 2020
a77fd4e
Update and rename Insights from Data with BigQuery: Challenge Lab to …
Ash3010 Oct 17, 2020
15df880
Merge pull request #24 from Ash3010/master
rahullrajesh Oct 17, 2020
9b1d584
Update Insights from Data with BigQuery: Challenge Lab(Updated task 9)
monishamandal02 Oct 24, 2020
6585c70
Merge pull request #26 from monishamandal02/master
rahullrajesh Oct 24, 2020
18b9eeb
Update Build and Secure Networks in Google Cloud: Challenge Lab
Ridham-2000 Oct 28, 2020
7246c7c
Merge pull request #28 from Ridham-2000/patch-2
rahullrajesh Oct 28, 2020
6785e36
Create Ensure Access & Identity in Google Cloud: Challenge Lab
rahullrajesh May 2, 2021
503af45
Update Ensure Access & Identity in Google Cloud: Challenge Lab
rahullrajesh May 3, 2021
a482ded
Update Ensure Access & Identity in Google Cloud: Challenge Lab
rahullrajesh May 3, 2021
6361d5a
Create Create ML Models with BigQuery ML: Challenge Lab
rahullrajesh May 13, 2021
7905c63
Create Build and Optimize Data Warehouses with BigQuery: Challenge Lab
rahullrajesh May 26, 2021
d351f26
Update Exploring the Public Cryptocurrency Datasets Available in BigQ…
sawantvikram Sep 17, 2021
c99fbe3
Merge pull request #34 from sawantvikram/patch-1
rahullrajesh Oct 1, 2021
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
101 changes: 101 additions & 0 deletions Build and Optimize Data Warehouses with BigQuery: Challenge Lab
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

CREATE OR REPLACE TABLE <YOUR_DATASET_ID>.<NEW_TABLE_NAME>
PARTITION BY date
OPTIONS(
partition_expiration_days=90,
description="oxford_policy_tracker table in the COVID 19 Government Response public dataset with an expiry time set to 90 days."
) AS
SELECT
*
FROM
`bigquery-public-data.covid19_govt_response.oxford_policy_tracker`
WHERE
alpha_3_code NOT IN ('GBR', 'USA')




ALTER TABLE <YOUR_DATASET_ID>.<YOUR_TABLE_NAME>
ADD COLUMN population INT64,
ADD COLUMN country_area FLOAT64,
ADD COLUMN mobility STRUCT<
avg_retail FLOAT64,
avg_grocery FLOAT64,
avg_parks FLOAT64,
avg_transit FLOAT64,
avg_workplace FLOAT64,
avg_residential FLOAT64
>


UPDATE
`<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>` t0
SET
population = t1.population
FROM
`bigquery-public-data.covid19_ecdc.covid_19_geographic_distribution_worldwide` t1
WHERE
CONCAT(t0.alpha_3_code, t0.date) = CONCAT(t1.country_territory_code, t1.date);



UPDATE
`<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>` t0
SET
t0.country_area = t1.country_area
FROM
`bigquery-public-data.census_bureau_international.country_names_area` t1
WHERE
t0.country_name = t1.country_name



UPDATE
`<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>` t0
SET
t0.mobility.avg_retail = t1.avg_retail
t0.mobility.avg_grocery = t1.avg_grocery
t0.mobility.avg_parks = t1.avg_parks
t0.mobility.avg_transit = t1.avg_transit
t0.mobility.avg_workplace = t1.avg_workplace
t0.mobility.avg_residential = t1.avg_residential
FROM
( SELECT country_region, date,
AVG(retail_and_recreation_percent_change_from_baseline) as avg_retail,
AVG(grocery_and_pharmacy_percent_change_from_baseline) as avg_grocery,
AVG(parks_percent_change_from_baseline) as avg_parks,
AVG(transit_stations_percent_change_from_baseline) as avg_transit,
AVG(workplaces_percent_change_from_baseline) as avg_workplace,
AVG(residential_percent_change_from_baseline) as avg_residential
FROM `bigquery-public-data.covid19_google_mobility.mobility_report`
GROUP BY country_region, date
) AS t1
WHERE
CONCAT(t0.country_name, t0.date) = CONCAT(t1.country_region, t1.date)




SELECT country_name, population
FROM `<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>`
WHERE population is NULL



SELECT country_name, country_area
FROM `<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>`
WHERE WHERE country_area IS NULL


SELECT DISTINCT country_name
FROM `<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>`
WHERE population is NULL
UNION ALL
SELECT DISTINCT country_name
FROM `<YOUR_DATASET_ID>.<YOUR_TABLE_NAME>`
WHERE WHERE country_area IS NULL
ORDER BY country_name ASC




14 changes: 7 additions & 7 deletions Build and Secure Networks in Google Cloud: Challenge Lab
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#WATCH FULL LAB ON : https://www.youtube.com/watch?v=22TczCBXyys


gcloud compute firewall-rules delete open-access
Step 1: gcloud compute firewall-rules delete open-access



gcloud compute instances start bastion
step 2: gcloud compute instances start bastion


gcloud compute firewall-rules create ssh-ingress --allow=tcp:22 --source-ranges 35.235.240.0/20 --target-tags ssh-ingress --network acme-vpc
step 3: gcloud compute firewall-rules create ssh-ingress --allow=tcp:22 --source-ranges 35.235.240.0/20 --target-tags ssh-ingress --network acme-vpc
gcloud compute instances add-tags bastion --tags=ssh-ingress --zone=us-central1-b


gcloud compute firewall-rules create http-ingress --allow=tcp:80 --source-ranges 0.0.0.0/0 --target-tags http-ingress --network acme-vpc
step 4: gcloud compute firewall-rules create http-ingress --allow=tcp:80 --source-ranges 0.0.0.0/0 --target-tags http-ingress --network acme-vpc

gcloud compute instances add-tags juice-shop --tags=http-ingress --zone=us-central1-b
step 5: gcloud compute instances add-tags juice-shop --tags=http-ingress --zone=us-central1-b



gcloud compute firewall-rules create internal-ssh-ingress --allow=tcp:22 --source-ranges 192.168.10.0/24 --target-tags internal-ssh-ingress --network acme-vpc
step 6: gcloud compute firewall-rules create internal-ssh-ingress --allow=tcp:22 --source-ranges 192.168.10.0/24 --target-tags internal-ssh-ingress --network acme-vpc

gcloud compute instances add-tags juice-shop --tags=internal-ssh-ingress --zone=us-central1-b
step 7 :gcloud compute instances add-tags juice-shop --tags=internal-ssh-ingress --zone=us-central1-b

150 changes: 150 additions & 0 deletions Create ML Models with BigQuery ML: Challenge Lab
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
Complete each of the sets of steps below to prepare the lab for the activity tracking assessment for each task in the lab.

Task 1: Create a dataset to store your machine learning models
It can be called any name to pass the test but for the remaining instructions to work use `austin` as the dataset name.

bq mk austin



Task 2: Create a forecasting BigQuery machine learning model.
Create the first ML model using a JOIN between two bike share tables. Again any names will work but keep them as ‘austin_1’ and ‘austin_2’ for the remaining instructions to work.

BigQuery Console Query Editor

CREATE OR REPLACE MODEL austin.location_model
OPTIONS
(model_type='linear_reg', labels=['duration_minutes']) AS
SELECT
start_station_name,
EXTRACT(HOUR FROM start_time) AS start_hour,
EXTRACT(DAYOFWEEK FROM start_time) AS day_of_week,
duration_minutes,
address as location
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
JOIN
`bigquery-public-data.austin_bikeshare.bikeshare_stations` AS stations
ON
trips.start_station_name = stations.name
WHERE
EXTRACT(YEAR FROM start_time) = 2018
AND duration_minutes > 0







Task 3: Create the second machine learning model.

BigQuery Console Query Editor
CREATE OR REPLACE MODEL austin.subscriber_model
OPTIONS
(model_type='linear_reg', labels=['duration_minutes']) AS
SELECT
start_station_name,
EXTRACT(HOUR FROM start_time) AS start_hour,
subscriber_type,
duration_minutes
FROM `bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
WHERE EXTRACT(YEAR FROM start_time) = 2018





Task 4: Evaluate the two machine learning models.

BigQuery Console Query Editor
Query 1

-- Evaluation metrics for location_model
SELECT
SQRT(mean_squared_error) AS rmse,
mean_absolute_error
FROM
ML.EVALUATE(MODEL austin.location_model, (
SELECT
start_station_name,
EXTRACT(HOUR FROM start_time) AS start_hour,
EXTRACT(DAYOFWEEK FROM start_time) AS day_of_week,
duration_minutes,
address as location
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
JOIN
`bigquery-public-data.austin_bikeshare.bikeshare_stations` AS stations
ON
trips.start_station_name = stations.name
WHERE EXTRACT(YEAR FROM start_time) = 2019)
)




Query 2
-- Evaluation metrics for subscriber_model
SELECT
SQRT(mean_squared_error) AS rmse,
mean_absolute_error
FROM
ML.EVALUATE(MODEL austin.subscriber_model, (
SELECT
start_station_name,
EXTRACT(HOUR FROM start_time) AS start_hour,
subscriber_type,
duration_minutes
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
WHERE
EXTRACT(YEAR FROM start_time) = 2019)
)








Task 5: Use the subscriber type machine learning model to predict average trip durations
Use the second model, that model (model austin_2 in this case) to to predict the average duration length of all trips from the busiest rental station in 2019 (based on the number of rentals per station in 2019) where the subscriber_type=’Single Trip’.


The following query will list busiest stations in descending order. The busiest station for 2019 was “21st & Speedway @PCL”.

BigQuery Console Query Editor
SELECT
start_station_name,
COUNT(*) AS trips
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips`
WHERE
EXTRACT(YEAR FROM start_time) = 2019
GROUP BY
start_station_name
ORDER BY
trips DESC





Then predict trip length.

BigQuery Console Query Editor
SELECT AVG(predicted_duration_minutes) AS average_predicted_trip_length
FROM ML.predict(MODEL austin.subscriber_model, (
SELECT
start_station_name,
EXTRACT(HOUR FROM start_time) AS start_hour,
subscriber_type,
duration_minutes
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips`
WHERE
EXTRACT(YEAR FROM start_time) = 2019
AND subscriber_type = 'Single Trip'
AND start_station_name = '21st & Speedway @PCL'))
53 changes: 53 additions & 0 deletions Ensure Access & Identity in Google Cloud: Challenge Lab
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

gcloud config set compute/zone us-east1-b

nano role-definition.yaml

title: "Edirca Storage Update"
description: "Add and update objects in Google Cloud Storage buckets"
includedPermissions:
- storage.buckets.get
- storage.objects.get
- storage.objects.list
- storage.objects.update
- storage.objects.create


gcloud iam roles create orca_storage_update \
--project $DEVSHELL_PROJECT_ID \
--file role-definition.yaml


gcloud iam service-accounts create orca-private-cluster-sa \
--display-name "Orca Private Cluster Service Account"

gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID \
--member serviceAccount:orca-private-cluster-sa@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com --role roles/monitoring.viewer

gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID \
--member serviceAccount:orca-private-cluster-sa@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com --role roles/monitoring.metricWriter

gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID \
--member serviceAccount:orca-private-cluster-sa@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com --role roles/logging.logWriter







gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID \
--member serviceAccount:orca-private-cluster-sa@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com --role projects/$DEVSHELL_PROJECT_ID/roles/orca_storage_update







gcloud container clusters create orca-test-cluster --network orca-build-vpc --subnetwork orca-build-subnet --service-account orca-private-cluster-sa@qwiklabs-gcp-01-73bc421e624d.iam.gserviceaccount.com --enable-master-authorized-networks --master-authorized-networks 192.168.10.2/32 --enable-ip-alias --enable-private-nodes --master-ipv4-cidr 10.142.0.0/28 --enable-private-endpoint



gcloud container clusters get-credentials orca-test-cluster --internal-ip --zone=us-east1-b
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ where outputs.output_satoshis = 19499300000000



-- SQL source from https://cloud.google.com/blog/product...
CREATE OR REPLACE TABLE lab.52 (balance NUMERIC) as
WITH double_entry_book AS (
-- debits
Expand All @@ -19,7 +18,6 @@ WITH double_entry_book AS (
array_to_string(outputs.addresses, ",") as address
, outputs.value as value
FROM `bigquery-public-data.crypto_bitcoin.outputs` as outputs

)
SELECT
sum(value) as balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
--port 8080


Step 3:kubect1 get pods
Step 3:kubectl get pods

Step 4:cat << EOF > startup.sh
#! /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion analyze-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
file_content = file.download_as_string()

# TBD: Create a Vision API image object called image_object
image_object = vision.types.Image(content=file_content)
image_object = vision.Image(content=file_content)
# Ref: https://googleapis.dev/python/vision/latest/gapic/v1/types.html#google.cloud.vision_v1.types.Image


Expand Down