1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.federatedcompute.services.data;
18 
19 import android.provider.BaseColumns;
20 
21 /** Contract for the task history table. Defines the table. */
22 public class TaskHistoryContract {
TaskHistoryContract()23     private TaskHistoryContract() {}
24 
25     /**
26      * Table containing federated compute task history. Each row in the table represents the
27      * contribution information for a given task.
28      */
29     public static class TaskHistoryEntry implements BaseColumns {
30         public static final String TABLE_NAME = "task_history";
31         public static final String JOB_ID = "job_id";
32         public static final String POPULATION_NAME = "population_name";
33         public static final String TASK_ID = "task_id";
34         // The timestamp when device uploads training result to GCS bucket done.
35         public static final String CONTRIBUTION_TIME = "contribution_time";
36         // The round number that device contribute training result successfully. The round number is
37         // returned by federated compute server when assigning task to device.
38         public static final String CONTRIBUTION_ROUND = "contribution_round";
39         // The total number that device has participate in the training per task per population.
40         public static final String TOTAL_PARTICIPATION = "total_participation";
41         public static final String CREATE_TASK_HISTORY_TABLE_STATEMENT =
42                 "CREATE TABLE IF NOT EXISTS "
43                         + TABLE_NAME
44                         + " ("
45                         + TaskHistoryEntry._ID
46                         + " INTEGER PRIMARY KEY, "
47                         + JOB_ID
48                         + " INTEGER NOT NULL,"
49                         + POPULATION_NAME
50                         + " TEXT NOT NULL,"
51                         + TASK_ID
52                         + " TEXT NOT NULL,"
53                         + CONTRIBUTION_TIME
54                         + " INTEGER NOT NULL,"
55                         + CONTRIBUTION_ROUND
56                         + " INTEGER NOT NULL,"
57                         + TOTAL_PARTICIPATION
58                         + " INTEGER NOT NULL)";
59     }
60 }
61