This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
private String extractResponseFor(View view) { | |
RadioGroup options = (RadioGroup) view.findViewById(R.id.radio_group); | |
int selection = options.getCheckedRadioButtonId(); | |
if (selection == -1) { | |
options.setBackgroundColor(getActivity().getResources().getColor(R.color.form_validation)); | |
isFormValid = false; | |
return getString(R.string.unknown); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeeklySurveyFragment extends SmartFragment implements WeeklySurveyView, OnWebserviceResponse { | |
... | |
@Override | |
public void onResume() { | |
super.onResume(); | |
appetiteDecreaseSeverityResponse = getView().findViewById(R.id.appetite_decrease_severity_response); | |
appetiteDecreaseInterferenceResponse = getView().findViewById(R.id.appetite_decrease_interference_response); | |
nauseaFrequencyResponse = getView().findViewById(R.id.nausea_frequency_response); | |
nauseaSeverityResponse = getView().findViewById(R.id.nausea_severity_response); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<RadioGroup | |
android:id="@+id/radio_group" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<include android:id="@+id/appetite_decrease_severity_response" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
layout="@layout/severity_question"/> | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
else: | |
if self.leader: | |
self.current_operation = string_operation | |
if self.current_operation.split(" ")[0] in ["set", "delete"]: | |
key_value_store.write_to_log(string_operation, term_absent=True) | |
broadcast(self, with_return_address(self, "append_entries ['" + self.current_operation + "']")) | |
while not self.current_operation_committed: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
elif string_operation.split(" ")[0] == "commit_entries": | |
# followers do this to update their logs. | |
stringified_logs_to_append = string_operation.replace("commit_entries ", "") | |
print("Preparing to commit: " + stringified_logs_to_append) | |
logs_to_append = ast.literal_eval(stringified_logs_to_append) | |
[key_value_store.write_to_state_machine(command, term_absent=True) for command in logs_to_append] | |
response = "Commit entries call successful!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def mark_updated(self, server_name): | |
self.followers_with_update_status[server_name] = True | |
trues = len(list(filter(lambda x: x is True, self.followers_with_update_status.values()))) | |
falses = len(list(filter(lambda x: x is False, self.followers_with_update_status.values()))) | |
if trues >= falses: | |
print("Committing entry: " + self.current_operation) | |
self.current_operation_committed = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
elif string_operation == "Append entries call successful!": | |
if self.leader: | |
self.mark_updated(server_name) | |
send_pending = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Server: | |
... | |
self.followers_with_update_status = {} | |
self.current_operation = '' | |
self.current_operation_committed = False | |
for server_name in other_server_names(name): | |
self.followers_with_update_status[server_name] = False | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if string_operation.split(" ")[0] == "append_entries": | |
# followers do this to update their logs. | |
stringified_logs_to_append = string_operation.replace("append_entries ", "") | |
print("Preparing to append: " + stringified_logs_to_append) | |
logs_to_append = ast.literal_eval(stringified_logs_to_append) | |
[key_value_store.write_to_log(log, term_absent=True) for log in logs_to_append] | |
print("State machine after appending: " + str(key_value_store.data)) | |
response = "Append entries call successful!" |