REON POCKETを持っていくべきか判断するアプリを作ってみた
タイトルのままです
htmlで動作するので、下段のコードをコピペしてhtml保存して適当に使ってください
壊れてたらAIに聞いて適当に直してください
アプリイメージ↓

ソースは以下
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>REON ASSIST</title>
<style>
:root {
--bg-color: #f3f4f6;
--card-bg: #ffffff;
--text-main: #1f2937;
--text-sub: #6b7280;
--accent-go: #2563eb;
--accent-stay: #4b5563;
}
body {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
margin: 0;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 360px;
background: var(--card-bg);
border-radius: 20px;
padding: 16px 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
text-align: center;
}
h1 {
font-size: 1rem;
margin: 0;
letter-spacing: 0.1em;
font-weight: 800;
}
.app-desc {
font-size: 0.65rem;
color: var(--text-sub);
margin: 4px 0 0 0;
line-height: 1.3;
}
.location-box {
margin-top: 8px;
margin-bottom: 12px;
cursor: pointer;
}
.location-tag {
font-size: 0.7rem;
color: var(--text-sub);
display: inline-block;
border-bottom: 1px dashed var(--text-sub);
padding-bottom: 1px;
}
.zip-form {
display: none;
justify-content: center;
gap: 6px;
margin: 8px 0;
}
.zip-form input {
width: 90px;
padding: 4px 8px;
font-size: 0.75rem;
border: 1px solid #d1d5db;
border-radius: 6px;
text-align: center;
}
.zip-form button {
padding: 4px 10px;
font-size: 0.75rem;
background: #374151;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
}
.result-box {
border-radius: 12px;
padding: 14px 16px;
margin-bottom: 12px;
color: #ffffff;
font-weight: bold;
transition: background-color 0.3s;
}
.result-title {
font-size: 2.6rem;
margin: 0;
letter-spacing: 0.05em;
line-height: 1;
}
.result-desc {
font-size: 0.8rem;
margin: 6px 0 0 0;
opacity: 0.95;
line-height: 1.4;
}
.weather-info {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 12px;
}
.info-card {
background: #f9fafb;
padding: 8px;
border-radius: 10px;
border: 1px solid #f3f4f6;
}
.info-label {
font-size: 0.65rem;
color: var(--text-sub);
margin-bottom: 2px;
}
.info-val {
font-size: 1.15rem;
font-weight: bold;
}
.criteria-box {
background: #f9fafb;
border-radius: 10px;
padding: 10px 12px;
margin-bottom: 12px;
text-align: left;
border: 1px solid #f3f4f6;
}
.criteria-title {
font-size: 0.7rem;
font-weight: bold;
margin: 0 0 4px 0;
}
.criteria-list {
font-size: 0.65rem;
color: var(--text-sub);
margin: 0;
padding-left: 10px;
line-height: 1.4;
}
.criteria-list li {
margin-bottom: 2px;
}
.forecast-box {
border-top: 1px dashed #e5e7eb;
padding-top: 10px;
margin-bottom: 10px;
text-align: left;
}
.forecast-title {
font-size: 0.7rem;
font-weight: bold;
margin: 0 0 6px 0;
color: var(--text-main);
}
.forecast-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 3px 0;
font-size: 0.75rem;
}
.forecast-day {
width: 55px;
color: var(--text-main);
font-weight: 500;
line-height: 1.2;
}
.forecast-weather {
flex-grow: 1;
color: var(--text-sub);
font-size: 0.7rem;
padding-left: 10px;
}
.badge {
padding: 2px 8px;
border-radius: 10px;
color: #ffffff;
font-size: 0.65rem;
font-weight: bold;
text-align: center;
width: 36px;
display: inline-block;
}
.badge.go { background-color: var(--accent-go); }
.badge.stay { background-color: var(--accent-stay); }
.status-footer {
font-size: 0.7rem;
color: var(--text-sub);
border-top: 1px solid #f3f4f6;
padding-top: 8px;
display: flex;
justify-content: center;
align-items: center;
gap: 4px;
}
.bg-go { background-color: var(--accent-go); }
.bg-stay { background-color: var(--accent-stay); }
.bg-error { background-color: #dc2626; }
</style>
</head>
<body>
<div class="container">
<h1>REON ASSIST</h1>
<p class="app-desc">これはREON POCKETを持ち出すべきか判断するアプリです</p>
<div class="location-box" onclick="toggleZipForm()">
<div class="location-tag">📍 <span id="locationText">特定中... (変更)</span></div>
</div>
<div id="zipForm" class="zip-form" onclick="event.stopPropagation()">
<input type="text" id="zipInput" placeholder="1000001" maxlength="8">
<button onclick="fetchByZip()">設定</button>
</div>
<div id="resultBox" class="result-box bg-stay">
<p class="result-title" id="decisionText">LOADING</p>
<p class="result-desc" id="reasonText">解析中...</p>
</div>
<div class="weather-info">
<div class="info-card">
<div class="info-label">本日の最高気温</div>
<div class="info-val" id="tempText">--°C</div>
</div>
<div class="info-card">
<div class="info-label">日中の平均湿度</div>
<div class="info-val" id="humidText">--%</div>
</div>
</div>
<div class="criteria-box">
<p class="criteria-title">📊 判断基準</p>
<ul class="criteria-list">
<li><strong>26°C未満</strong>:不要(STAY)</li>
<li><strong>26〜31°C</strong>:最適環境(GO)</li>
<li><strong>32°C以上(高湿度)</strong>:屋内・電車内の汗止め用(GO)</li>
<li><strong>35°C以上 または 低湿度猛暑</strong>:REON POCKETだけではカバーできない外気温です(STAY)</li>
</ul>
</div>
<div class="forecast-box">
<p class="forecast-title">🔮 3日間予報</p>
<div id="forecastContainer"></div>
</div>
<div class="status-footer">
<span id="statusIcon">⏳</span>
<span id="timeText">同期中...</span>
</div>
</div>
<script>
const DEFAULT_LAT = 35.6895;
const DEFAULT_LON = 139.6917;
// 起動時の初期化をより安全に修正
document.addEventListener('DOMContentLoaded', () => {
autoJudge();
});
function autoJudge() {
if (!navigator.geolocation) {
fallbackToDefault("GPS非対応環境。東京で判定中", "東京都新宿区");
return;
}
navigator.geolocation.getCurrentPosition(
async (position) => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
const placeName = await getPlaceName(lat, lon);
document.getElementById('locationText').innerText = placeName;
fetchWeatherData(lat, lon, "現在地");
},
() => {
// 位置情報エラー時はデフォルト(東京)を読み込みつつフォームを表示
fallbackToDefault("位置情報がオフです。郵便番号を入力してください", "東京都新宿区");
toggleZipForm(true);
},
{ enableHighAccuracy: false, timeout: 5000 }
);
}
function toggleZipForm(forceShow = false) {
const form = document.getElementById('zipForm');
form.style.display = (form.style.display === 'flex' && !forceShow) ? 'none' : 'flex';
}
// デバッグ項目:緯度経度の逆引きAPI(zipcloud)のレスポンスから数学的に正確な中心値を算出する形に安全化
async function fetchByZip() {
const zip = document.getElementById('zipInput').value.replace('-', '').trim();
if (!/^\d{7}$/.test(zip)) {
alert('郵便番号は7桁で入力してください。');
return;
}
document.getElementById('reasonText').innerText = "地域データを検索中...";
try {
// 信頼性の高い国産APIのみで完結させ、エラーの起きやすい海外地図リバースAPIへの依存度を排除
const res = await fetch(`https://zipcloud.ibsnet.co.jp/api/search?zipcode=${zip}`);
const data = await res.json();
if (data.status === 200 && data.results && data.results.length > 0) {
const result = data.results[0];
const name = result.address1 + result.address2; // ◯◯県◯◯市
// 地図検索APIの制限を回避するため、User-Agentの代わりに安全なパラメータをセット
const geoRes = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(name)}&limit=1`, {
headers: { 'Accept-Language': 'ja' }
});
const geoData = await geoRes.json();
if (geoData && geoData.length > 0) {
const lat = parseFloat(geoData[0].lat);
const lon = parseFloat(geoData[0].lon);
document.getElementById('locationText').innerText = name + (result.address3 ? result.address3 : "");
toggleZipForm(false);
fetchWeatherData(lat, lon, "指定エリア");
} else {
// 万が一地図座標が引けない場合は日本の中心付近にフォールバック
throw new Error();
}
} else {
alert('該当する郵便番号が見つかりませんでした。');
document.getElementById('reasonText').innerText = "待機中";
}
} catch (e) {
alert('位置情報の取得でエラーが発生しました。別の7桁の郵便番号をお試しください。');
document.getElementById('reasonText').innerText = "待機中";
}
}
async function getPlaceName(lat, lon) {
try {
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lon}&accept-language=ja`, {
headers: { 'Accept-Language': 'ja' }
});
const data = await res.json();
return data.address ? (data.address.province || data.address.state || "") + (data.address.city || data.address.town || data.address.suburb || "") : "現在地";
} catch { return "現在地"; }
}
function fallbackToDefault(msg, loc) {
document.getElementById('reasonText').innerText = msg;
document.getElementById('locationText').innerText = loc;
fetchWeatherData(DEFAULT_LAT, DEFAULT_LON, "デフォルト");
}
async function fetchWeatherData(lat, lon, label) {
try {
const response = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&hourly=temperature_2m,relative_humidity_2m&timezone=Asia%2FTokyo`);
const data = await response.json();
if (!data || !data.hourly) {
throw new Error("気象データの形式が不正です");
}
const dailyData = {};
data.hourly.time.forEach((timeStr, index) => {
const dateKey = timeStr.substring(0, 10);
const temp = data.hourly.temperature_2m[index];
const humid = data.hourly.relative_humidity_2m[index];
const hour = parseInt(timeStr.substring(11, 13), 10);
if (!dailyData[dateKey]) {
dailyData[dateKey] = { maxTemp: -99, totalHumid: 0, humidCount: 0 };
}
if (temp > dailyData[dateKey].maxTemp) {
dailyData[dateKey].maxTemp = temp;
}
if (hour >= 9 && hour <= 18) {
dailyData[dateKey].totalHumid += humid;
dailyData[dateKey].humidCount++;
}
});
const sortedDates = Object.keys(dailyData).sort();
const todayKey = sortedDates[0];
const todayMaxTemp = Math.round(dailyData[todayKey].maxTemp);
const todayAvgHumid = dailyData[todayKey].humidCount > 0 ? Math.round(dailyData[todayKey].totalHumid / dailyData[todayKey].humidCount) : 50;
runJudgeLogic(todayMaxTemp, todayAvgHumid, label);
renderForecast(sortedDates.slice(1, 4), dailyData);
} catch (error) {
console.error(error);
document.getElementById('resultBox').className = "result-box bg-error";
document.getElementById('decisionText').innerText = "ERROR";
document.getElementById('reasonText').innerText = "天気データの取得に失敗";
}
}
function calculateDecision(maxTemp, avgHumid) {
if (maxTemp < 26 || maxTemp >= 35) return "STAY";
if (maxTemp >= 26 && maxTemp <= 31) return "GO";
if (maxTemp >= 32) return avgHumid >= 65 ? "GO" : "STAY";
return "STAY";
}
function runJudgeLogic(maxTemp, avgHumid, label) {
document.getElementById('tempText').innerText = `${maxTemp}°C`;
document.getElementById('humidText').innerText = `${avgHumid}%`;
const timeStr = new Date().toLocaleTimeString('ja-JP', { hour: '2-digit', minute: '2-digit' });
const decision = calculateDecision(maxTemp, avgHumid);
let reason = "", bg = "bg-stay";
if (maxTemp < 26) {
reason = "過ごしやすい気温です。デバイスは不要です。";
} else if (maxTemp >= 26 && maxTemp <= 31) {
bg = "bg-go";
reason = "冷却効率が最も高まる最適コンディションです。";
} else if (maxTemp >= 35) {
reason = "酷暑すぎて、REON POCKETだけではカバーできない外気温です。";
} else if (maxTemp >= 32) {
if (avgHumid >= 65) {
bg = "bg-go";
reason = "高湿度です。屋内や電車内での汗引き用に携行を推奨。";
} else {
reason = "空気はドライです。放熱効率が落ちるため不要です。";
}
}
document.getElementById('decisionText').innerText = decision;
document.getElementById('reasonText').innerText = reason;
document.getElementById('resultBox').className = `result-box ${bg}`;
document.getElementById('statusIcon').innerText = "🔄";
document.getElementById('timeText').innerText = `${timeStr} 更新 (${label})`;
}
function renderForecast(forecastDates, dailyData) {
const container = document.getElementById('forecastContainer');
container.innerHTML = "";
const dayLabels = ["明日", "明後日", "3日後"];
forecastDates.forEach((dateStr, index) => {
const data = dailyData[dateStr];
const maxTemp = Math.round(data.maxTemp);
const avgHumid = data.humidCount > 0 ? Math.round(data.totalHumid / data.humidCount) : 50;
const decision = calculateDecision(maxTemp, avgHumid);
const displayDate = `${parseInt(dateStr.substring(5, 7), 10)}/${parseInt(dateStr.substring(8, 10), 10)}`;
const row = document.createElement('div');
row.className = 'forecast-row';
row.innerHTML = `
<div class="forecast-day">${dayLabels[index]}<span style="font-size:0.6rem; color:var(--text-sub); display:block;">${displayDate}</span></div>
<div class="forecast-weather">${maxTemp}°C / ${avgHumid}%</div>
<div><span class="badge ${decision.toLowerCase()}">${decision}</span></div>
`;
container.appendChild(row);
});
}
</script>
</body>
</html>
このアプリはGeminiくんが通勤時間に作ってくれました