2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

✨ 一行日記アプリ開発の舞台裏

2
Last updated at Posted at 2025-08-26

🌟 ONE LINE DIARY

ONE LINE DIARY
簡易的なログイン機能付き
※ Render(PostgreSQL)の無料枠都合上、2025年内まで公開予定

記事構成

  • :heart: 感情分岐の内部構造 ~背景色を変更しよう~
  • :sparkling_heart: 感情分岐の内部構造 ~絵文字を表示!~
  • :writing_hand: 画面のデザイン ~ログイン画面のスマホ対応~
  • :shamrock: 画面のデザイン ~色とフォントと優しさと~
  • :books: 関連記事

:heart: 感情分岐の内部構造 ~背景色を変更しよう~

テーマと方向性

  • 最近の気分を色で可視化して楽しめる
  • 自己認識を深めるきっかけとしても効果的
  • 過去全体を振り返ると平均化されるため、直近20件のみを対象
  • 投稿は1行の短めな内容を想定しており、グラデーションを反映するには20件程度は必要
  • 投稿数が少ない場合は中立で補完し、スムーズな色変化を実現
# --- 感情分析 ---
def analyze_sentiment(text):
    pos_count = 0
    neg_count = 0
    for word,category in word_dict.items():
        if word in text:
            if category == 'positive':
                pos_count += 1
            else:
                neg_count += 1
    total = pos_count + neg_count
    if total == 0:
        return 0.5  # 中立  (辞書にない単語のみの場合)
    return pos_count / total  # ポジティブ度を返す

# 感情分析を21ランクの整数に変換
def sentiment_to_rank(pos_ratio):
    return int(pos_ratio * 20)

# 感情ランクに対して色を取得
def get_color_for_sentiment(rank):
    return colors[rank]
# --- 背景色決定 ---
@app.context_processor
def inject_background_color():
    if not current_user.is_authenticated:
        return dict(background_color="#F7F7F0")

    # ユーザーの直近20件を取得
    recent_posts = Post.query.filter_by(user_id=current_user.id).order_by(Post.date_created.desc()).limit(20).all()
    ratios = [analyze_sentiment(p.content) for p in recent_posts]

    # 投稿が20件に満たない場合は、中立0.5で補完
    remaining = 20 - len(ratios)
    if remaining > 0:
        ratios.extend([0.5] * remaining)

    # 平均を計算して色を決定
    avg_ratio = sum(ratios) / len(ratios)
    overall_color = get_color_for_sentiment(sentiment_to_rank(avg_ratio))

    return dict(background_color=overall_color)

:sparkling_heart: 感情分岐の内部構造 ~絵文字を表示!~

テーマと方向性

  • 背景色変更によりネガティブな内容ばかり投稿していることに落ち込む可能性に配慮し、内容に応じたアイコンを表示、ラベリング効果でストレス軽減を目指す
  • 顔アイコンより抽象的な「天気アイコン☀️☁️☂️」を採用
  • CSVに単語がない場合は☁️、一つでも合致すれば☀️or☂️
  • 天気アイコンと背景色の変化が一致して統一感UP
# --- 絵文字解析 ---
def analyze_emoji(text: str) -> str:
    score = 0
    for word, category in word_dict.items():
        if word in text:
            score += 1 if category == "positive" else -1

    if score > 0:
        return "\u2600"  # ☀️ ポジティブ
    elif score < 0:
        return "\u2602"  # ☂️ ネガティブ
    else:
        return "\u2601"  # ☁️ ニュートラル

:writing_hand: 画面のデザイン ~ログイン画面のスマホ対応~

方針

  • ログイン画面と新規登録画面が似ていると間違いやすいため、デザインに変化を付け区別
    • ログイン画面はユーザー名とパスワードのボックスを横並び
    • 新規登録画面は、ボックスを縦積み
  • スマホで見やすいようフォームを調整し、意図しない改行を防止
説明文
/* .css内で構造を指定 */
/* スマホ(600px以下)では縦並びに切り替え */
@media (max-width: 600px) {
    .login-form {
        flex-direction: column;
        align-items: stretch; /* 幅いっぱい */
    }
    .login-form button {
        align-self: flex-start; /* ボタンを左寄せ */
    }
}
<!-- ログインフォーム -->
<form method="post" class="login-form">
    <div class="form-row">
        <label for="username">ユーザー名</label>
        <input type="text" name="username" id="username">
    </div>

    <div class="form-row">
        <label for="password">パスワード</label>
        <input type="password" name="password" id="password">
    </div>

    <button type="submit">ログイン</button>
</form>

:shamrock: 画面のデザイン ~色とフォントと優しさと~

方針と方向性

  • 「ユーザーに優しさを」を意識して、全体的に優しい色使いを採用

  • 背景色は21段階に設定し、変化を楽しめるように

  • 背景はペールトーンの色合いで、文字はブラウンで柔らかく表示

  • 背景との明度差を十分に確保し、文字の可読性が劣らないように配慮

  • タイトル文字は本文文字より僅かに濃くしてアクセントを付与
    背景設定.png

  • 文字フォントは、一般的な字体の中でも丸みがあり柔らかい印象の"zen丸ゴシック"

  • 日記のタイトル「ONE LINE DIARY」は、柔らかさとアクセントを両立する"Unbounded"

  • アプリ紹介の画像も柔らかさを意識。矢印はクレヨン風で癒し系、背景色はアプリの背景に合わせて一体感を演出

:books: 関連記事

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?