Public
Edited
May 19, 2023
Insert cell
Insert cell
calculateMonthlyStorageCost({
numUsers: 1000,
bigObjectSizeMB: 6,
numBigObjectUpdatesPerDay: 20,
photoSizeMB: 3,
audioSizeMB: 5,
videoSizeMB: 50,
})
Insert cell
function calculateMonthlyStorageCost(params) {
// Extract parameters
const { numUsers, bigObjectSizeMB, numBigObjectUpdatesPerDay, photoSizeMB, audioSizeMB, videoSizeMB } = params;
// Define constants (sizes are in MB)
const numDaysPerMonth = 30; // Roughly

// Convert MB to GB (since S3 pricing is per GB)
const bigObjectSizeGB = bigObjectSizeMB / 1024;
const photoSizeGB = photoSizeMB / 1024;
const audioSizeGB = audioSizeMB / 1024;
const videoSizeGB = videoSizeMB / 1024;
// Calculate total storage per user
const bigObjectStoragePerMonthGB = numBigObjectUpdatesPerDay * numDaysPerMonth * bigObjectSizeGB;
const photoStoragePerMonthGB = photoSizeGB; // Assume 1 photo upload/download per day
const audioStoragePerMonthGB = audioSizeGB; // Assume 1 audio upload/download per day
const videoStoragePerMonthGB = videoSizeGB; // Assume 1 video upload/download per day
const totalStoragePerUserPerMonthGB = bigObjectStoragePerMonthGB + photoStoragePerMonthGB + audioStoragePerMonthGB + videoStoragePerMonthGB;

// Calculate total storage for all users
const totalStorageAllUsersPerMonthGB = numUsers * totalStoragePerUserPerMonthGB;
// S3 Standard storage cost in US East (N. Virginia) as of September 2021
const costPerGBPerMonth = 0.023; // This can change

// Calculate total cost
const totalCostPerMonth = totalStorageAllUsersPerMonthGB * costPerGBPerMonth;

return totalCostPerMonth;
}
Insert cell
viewof apiKey = Inputs.text({label: "WeatherAPI.com API Key", placeholder: "Your API Key", value: ""})
Insert cell
getCurrentWeatherDescription()
Insert cell
async function getCurrentWeatherDescription() {
const weatherData = await getWeatherData();
return `Weather: ${weatherData.temperature}°C, ${weatherData.condition.toLowerCase()}, ${weatherData.cloud}% cloud coverage, ${weatherData.humidity}% humidity, wind ${weatherData.windKph} km/h, UV index ${weatherData.uv}`;
}
Insert cell
async function getWeatherData() {
const url = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=47.34821170513242,19.094129997559854&aqi=no`;

const response = await fetch(url);
const data = await response.json();
return {
temperature: data.current.temp_c,
temperatureFeelsLike: data.current.feelslike_c,
humidity: data.current.humidity,
cloud: data.current.cloud,
condition: data.current.condition.text,
windKph: data.current.wind_kph,
uv: data.current.uv,
}
}
Insert cell
async function getWeatherForecast() {
const url = `https://api.weatherapi.com/v1/forecast.json?key=${apiKey}&q=47.34821170513242,19.094129997559854&days=1&aqi=no&alerts=no`;
const response = await fetch(url);
const data = await response.json();
return data;
}
Insert cell
getWeatherForecast()
Insert cell
async function getWeatherForecastDescription() {
return (await getWeatherForecast()).forecast.forecastday[0].hour
.filter(hour => ["06:00", "10:00", "14:00", "18:00", "20:00"].includes(hour.time.slice(-5)))
.map(hour => ({
time: hour.time.slice(-5),
temperature: hour.temp_c,
condition: hour.condition.text,
windKph: hour.wind_kph,
uv: hour.uv
}))
.map(hour => `${hour.time}: ${hour.temperature}°C, ${hour.condition}, wind ${hour.windKph} km/h, UV index ${hour.uv}`)
.join("\n");
}
Insert cell
getWeatherForecastDescription()
Insert cell
arr = [1, 2, 3, 4, 5]
Insert cell
arr.reduce((acc, item) => acc + ", " + item, "")
Insert cell
arr.reduceRight((acc, item) => acc + ", " + item, "")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more