愛記システムの基本設計:DApps側である愛記システム 愛の行動の促進 動機付けのタイミング | 続・ティール組織 研究会のブログ

続・ティール組織 研究会のブログ

ティール組織が話題になっているが、具現化するにはどうしたらよいか?
その研究を続けるにあたり、さらに次の形態である、続・ティール組織なるものまで視野に入れ、具体的な施策・行動内容を研究・支援する会。

先までは、"愛記"についての記載で、どのようにブロックチェーンSNSに組み込んで実装していけばよいのか、概念的なところからアプローチ方法を記載していった。概念設計としてはひとまず終えた。次は、フェデレーションモデル全体の基本設計といえるところまで、基本設計書に着手できるようなところまで、概念を具体化していきたい。そして、それにつながるDApps側である「愛記システム」を、Pythonプログラムで開発していきたい。

 

愛の行動のPL,BSを決算書として、個人単位、市町村単位、で公表するような愛記システムというものを考えている。愛の行動のデータベースはブロックチェーンのプログラムであり、日々の愛の行動による愛貨の移動を決算書にまとめていきたい。なお、市町村のブロックチェーンのプログラムは以前にも記載している。その市町村のブロックチェーンのプログラムにつながる愛記システムを、DApps側であるPythonプログラムとして設計したい。その場合、基本設計をどのような手順で進めていけばよいか、詳しく見ていこう。

 

愛記システムを設計するための基本手順を以下に示す。このシステムは、Pythonを用いて市町村のブロックチェーンと連携し、個人および市町村単位での愛の行動のデータを収集、記録し、決算書(PL、BS)として公表するものである。

基本設計のステップ

  1. 要件定義
  2. アーキテクチャ設計
  3. データベース設計
  4. API設計
  5. ブロックチェーンインターフェース
  6. 決算書の生成
  7. フロントエンド開発
  8. テストとデプロイ

基本設計の各ステップを順番に進めることで、ブロックチェーンとDAppsとして繋がる「愛記システム」の詳細な設計が可能になる。各ステップでは、関係者との協議やレビューを通じて設計内容を確定していくことが重要である。

1.要件定義

まず、基本設計の最初のステップである要件定義をしていきたい。どのような機能が必要か、どのような問題を解決するのかを洗い出したい。要件定義はシステム設計の最初の重要なステップであり、システムが解決するべき問題と、必要な機能を明確に定義するプロセスである。以下に、愛記システムのプログラムに必要な機能と解決すべき問題を列挙してみよう。

機能要件

  1. 愛の行動の記録

  2. 愛貨の移動の記録

  3. 決算書の生成

  4. 個人および市町村単位でのデータの集約

  5. データのブロックチェーンへの記録と取得

  6. 愛貨の管理

  7. ユーザー管理

  8. 通知機能

  9. レポート機能

  10. ダッシュボード

非機能要件

  1. セキュリティ

  2. 可用性

  3. パフォーマンス

  4. スケーラビリティ

  5. ユーザビリティ

  6. コンプライアンス

解決すべき問題

  1. 透明性と信頼性の確保

  2. データの一元管理

  3. 愛の行動の促進

  4. 評価制度の確立

  5. データのセキュリティとプライバシーの保護

これらの要件を基に、愛記システムの基本設計を進めていくことが重要である。次のステップでは、これらの要件を具体的なアーキテクチャ設計に反映していくことになる。まずは、要件定義の解決すべき問題を一つずつクリアにしていきたい。

愛の行動の促進

愛の行動の促進は、愛記システムの主要な目的の一つである。これを達成するためには、ユーザーが積極的に愛の行動を取る動機付けを行い、その行動を記録し、報酬やフィードバックを提供する必要がある。以下に具体的な設計案を示す。

1. 動機付けのタイミングと方法

タイミング

  • 新規ユーザー登録時: ウェルカムメッセージと初回ボーナス
  • 定期的なリマインダー: 日々のリマインダー通知
  • 特別なイベント時: 特定のイベントやキャンペーン

方法

  • 通知機能: アプリやメールによるリマインダーと通知
  • 報酬制度: ポイントや愛貨のボーナス
  • ランキングシステム: ユーザー同士の競争心を刺激

2. 愛の行動の記録

タイミング

  • ユーザーが愛の行動を行ったとき: 即時に記録
  • 他者がユーザーの行動を認証したとき: 承認後に記録

方法

  • モバイルアプリまたはWebポータル: ユーザーが愛の行動を入力
  • QRコードスキャン: 簡単に行動を記録

3. フィードバックと報酬

タイミング

  • 行動記録時: 行動の記録後即時
  • 定期的な報酬: 週次・月次の集計に基づく報酬

方法

  • ポイントシステム: 行動に応じたポイントの付与
  • バッジや称号: 特定の行動に対するバッジの付与
  • 愛貨の付与: 特定の行動に対する愛貨の報酬

4. コミュニティの形成

タイミング

  • 定期的なイベント: 月次・年次のイベント
  • 特別な達成時: 特定の目標を達成した時

方法

  • フォーラム: ユーザー同士が交流できるフォーラム
  • イベント: オンラインまたはオフラインのイベントの開催
  • チャレンジ: ユーザーが参加できるチャレンジやミッション
     

動機付けのタイミングと方法

1. 新規ユーザー登録時

タイミング: ユーザーが新規登録を完了した時点

方法:

  • ウェルカムメッセージ: ユーザー登録後に送信
  • 初回ボーナス: ユーザー登録後に自動的にアカウントにボーナスポイントや愛貨を付与

プログラム例:
from flask import Flask, request, jsonify
from pymongo import MongoClient
from datetime import datetime
import smtplib
from email.mime.text import MIMEText

app = Flask(__name__)

# MongoDB接続
client = MongoClient('mongodb://localhost:27017/')
db = client.love_currency_db
users_collection = db.users

# SMTPサーバー設定
SMTP_SERVER = 'smtp.example.com'
SMTP_PORT = 587
SMTP_USER = 'your_email@example.com'
SMTP_PASSWORD = 'your_password'

def send_email(to_address, subject, message):
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = SMTP_USER
    msg['To'] = to_address

    with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
        server.starttls()
        server.login(SMTP_USER, SMTP_PASSWORD)
        server.sendmail(SMTP_USER, to_address, msg.as_string())

@app.route('/register', methods=['POST'])
def register_user():
    data = request.json
    user_id = data.get('user_id')
    email = data.get('email')
    profile = data.get('profile')
    auth_info = data.get('auth_info')

    user_data = {
        "user_id": user_id,
        "email": email,
        "profile": profile,
        "auth_info": auth_info,
        "points": 100,  # 初回ボーナス
        "registration_date": datetime.utcnow()
    }

    users_collection.insert_one(user_data)

    # ウェルカムメッセージを送信
    send_email(email, "Welcome to Love Currency!", "Thank you for registering. Here is your welcome bonus of 100 points!")

    return jsonify({"message": "User registered successfully and welcome email sent."}), 200

if __name__ == '__main__':
    app.run(debug=True)
 

2. 定期的なリマインダー

タイミング: 毎日定時(例: 午前9時)

方法:

  • リマインダー通知: アプリのプッシュ通知またはメール

プログラム例:
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta

scheduler = BackgroundScheduler()

def send_daily_reminder():
    users = users_collection.find()
    for user in users:
        email = user.get('email')
        send_email(email, "Daily Reminder", "Don't forget to perform an act of love today!")

scheduler.add_job(send_daily_reminder, 'interval', days=1, start_date='2022-01-01 09:00:00')
scheduler.start()
 

3. 特別なイベント時

タイミング: 特定のイベントやキャンペーン開始時

方法:

  • イベント通知: アプリのプッシュ通知またはメール
  • イベントボーナス: イベントに参加したユーザーにボーナスポイントや愛貨を付与

プログラム例:
@app.route('/start_event', methods=['POST'])
def start_event():
    event_name = request.json.get('event_name')
    bonus_points = request.json.get('bonus_points')

    users = users_collection.find()
    for user in users:
        email = user.get('email')
        user_id = user.get('user_id')
        # イベント通知を送信
        send_email(email, "Special Event: " + event_name, f"Join our special event and earn {bonus_points} bonus points!")
        # ボーナスポイントを付与
        users_collection.update_one({"user_id": user_id}, {"$inc": {"points": bonus_points}})
    
    return jsonify({"message": "Event started and notifications sent."}), 200
 

4. 地域通貨の特性を利用

タイミング: 愛貨の使用時

方法:

  • 地域居住者や企業に対する参加制限
  • 地域ごとに愛貨の使用条件を設定
  • 他地域との愛貨交換が可能
プログラム例:
from flask import Flask, request, jsonify
from pymongo import MongoClient, ASCENDING
from datetime import datetime

app = Flask(__name__)

# MongoDB接続
client = MongoClient('mongodb://localhost:27017/')
db = client.love_currency_db

# コレクションの定義
users_collection = db.users
actions_collection = db.love_actions
movements_collection = db.currency_movements
municipalities_collection = db.municipalities

# インデックスの作成
users_collection.create_index([('user_id', ASCENDING)], unique=True)
municipalities_collection.create_index([('municipality_id', ASCENDING)], unique=True)

# ユーザーの地域登録
@app.route('/register_user', methods=['POST'])
def register_user():
    data = request.json
    user_id = data.get('user_id')
    profile = data.get('profile')
    auth_info = data.get('auth_info')
    municipality_id = data.get('municipality_id')
    
    if user_id and profile and auth_info and municipality_id:
        user_data = {
            "user_id": user_id,
            "profile": profile,
            "auth_info": auth_info,
            "balance": 0,
            "municipality_id": municipality_id
        }
        users_collection.insert_one(user_data)
        return jsonify({"message": "User registered successfully."}), 200
    return jsonify({"message": "User registration failed."}), 400

# 愛貨の使用
@app.route('/use_love_currency', methods=['POST'])
def use_love_currency():
    data = request.json
    user_id = data.get('user_id')
    amount = data.get('amount')
    municipality_id = data.get('municipality_id')
    
    if user_id and amount and municipality_id:
        user = users_collection.find_one({"user_id": user_id})
        if user and user["municipality_id"] == municipality_id and user["balance"] >= amount:
            users_collection.update_one(
                {"user_id": user_id},
                {"$inc": {"balance": -amount}}
            )
            return jsonify({"message": "Love currency used successfully."}), 200
        return jsonify({"message": "Failed to use love currency."}), 400
    return jsonify({"message": "Invalid request."}), 400

# 愛貨の交換
@app.route('/exchange_love_currency', methods=['POST'])
def exchange_love_currency():
    data = request.json
    sender_id = data.get('sender_id')
    receiver_id = data.get('receiver_id')
    amount = data.get('amount')
    
    if sender_id and receiver_id and amount:
        sender = users_collection.find_one({"user_id": sender_id})
        receiver = users_collection.find_one({"user_id": receiver_id})
        
        if sender and receiver and sender["balance"] >= amount:
            users_collection.update_one({"user_id": sender_id}, {"$inc": {"balance": -amount}})
            users_collection.update_one({"user_id": receiver_id}, {"$inc": {"balance": amount}})
            return jsonify({"message": "
            "Currency exchanged successfully."}), 200
        return jsonify({"message": "Failed to exchange love currency."}), 400
    return jsonify({"message": "Invalid request."}), 400

# ユーザーの愛の行動記録
@app.route('/record_love_action', methods=['POST'])
def record_love_action():
    data = request.json
    user_id = data.get('user_id')
    action_content = data.get('action_content')
    location = data.get('location')
    participants = data.get('participants')
    action_level = data.get('action_level')
    
    if user_id and action_content and location and participants and action_level:
        action_data = {
            "user_id": user_id,
            "action_content": action_content,
            "timestamp": datetime.utcnow(),
            "location": location,
            "participants": participants,
            "action_level": action_level,
            "love_currency": calculate_love_currency(action_level)
        }
        actions_collection.insert_one(action_data)
        users_collection.update_one(
            {"user_id": user_id},
            {"$inc": {"balance": action_data["love_currency"]}}
        )
        return jsonify({"message": "Love action recorded successfully."}), 200
    return jsonify({"message": "Failed to record love action."}), 400

# 愛の行動レベルに応じた愛貨の計算
def calculate_love_currency(action_level):
    level_to_currency = {
        1: 10,
        2: 40,
        3: 70,
        4: 100,
        5: 130,
        6: 160,
        7: 190,
        8: 220,
        9: 250,
        10: 280
    }
    return level_to_currency.get(action_level, 0)

# 地域ごとの愛貨使用条件の確認
@app.route('/check_eligibility', methods=['GET'])
def check_eligibility():
    user_id = request.args.get('user_id')
    municipality_id = request.args.get('municipality_id')
    
    if user_id and municipality_id:
        user = users_collection.find_one({"user_id": user_id})
        if user and user["municipality_id"] == municipality_id:
            return jsonify({"eligible": True}), 200
        return jsonify({"eligible": False}), 400
    return jsonify({"message": "Invalid request."}), 400

if __name__ == "__main__":
    app.run(debug=True)
 

5. ユーザー同士の競争心を刺激するランキングシステム

タイミング: 月次、年次

方法:

  • 定期的にランキングを作成し、上位者を表彰

プログラム例:
@app.route('/monthly_ranking', methods=['GET'])
def monthly_ranking():
    start_date = datetime.utcnow().replace(day=1)
    end_date = datetime.utcnow()

    top_users = users_collection.find({
        "actions.timestamp": {"$gte": start_date, "$lt": end_date}
    }).sort("points", -1).limit(10)

    ranking = [{"user_id": user["user_id"], "points": user["points"]} for user in top_users]
    return jsonify(ranking), 200

@app.route('/award_ceremony', methods=['POST'])
def award_ceremony():
    top_users = request.json.get('top_users')
    for user_id in top_users:
        user = users_collection.find_one({"user_id": user_id})
        email = user.get('email')
        send_email(email, "Award Ceremony", "Congratulations! You have been awarded for your actions of love.")
    return jsonify({"message": "Award notifications sent."}), 200
 

全体的な流れ

  1. 新規ユーザー登録時

    • ユーザー登録APIが呼ばれ、ウェルカムメッセージと初回ボーナスが送信される
  2. 定期的なリマインダー

    • APSchedulerを使用して、毎日定時にリマインダー通知が送信される
  3. 特別なイベント時

    • イベントAPIが呼ばれ、条件を満たしたユーザーにボーナスが付与される
  4. 地域通貨の特性を利用

    • 地域ごとの愛貨の使用条件の確認APIが呼ばれ、行動が記録され、愛貨がやりとりされる
  5. ランキングと表彰

    • ランキングAPIが呼ばれ、定期的にランキングが作成され、上位者が表彰される

これにより、全国民が自発的に愛の行動を起こすことを促進し、システム全体の活性化を図ることができる。
 

 

いかがであろうか、今回は動機付けのタイミングと方法について記載した。ここは次の愛貨移動や決算書にも関わってくることなので、そこで詳しく記載したい。